summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Mandaleeka <adityam@microsoft.com>2016-03-07 15:16:27 -0800
committerAditya Mandaleeka <adityam@microsoft.com>2016-03-19 20:56:14 -0700
commit51033e700c1fb5854962f1f31ebc4b144d5d49d7 (patch)
tree89eae979f459fb1a0c59d9b306c8f9afd40c91f0
parent586ce538403c1b859f73d97abec9bb4bfad4cab7 (diff)
downloadcoreclr-51033e700c1fb5854962f1f31ebc4b144d5d49d7.tar.gz
coreclr-51033e700c1fb5854962f1f31ebc4b144d5d49d7.tar.bz2
coreclr-51033e700c1fb5854962f1f31ebc4b144d5d49d7.zip
Open source more threading tests.
-rw-r--r--tests/src/baseservices/threading/interlocked/add/add.cs41
-rw-r--r--tests/src/baseservices/threading/interlocked/add/add.csproj41
-rw-r--r--tests/src/baseservices/threading/interlocked/add/interlockedaddintwithsubtract.cs107
-rw-r--r--tests/src/baseservices/threading/interlocked/add/interlockedaddintwithsubtract.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/app.config (renamed from tests/src/baseservices/threading/readerwriterlockslim/app.config)6
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/intdeccheckreturn.cs23
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/intdeccheckreturn.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/intinccheckreturn.cs23
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/intinccheckreturn.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/longdeccheckreturn.cs22
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/longdeccheckreturn.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/longinccheckreturn.cs22
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/longinccheckreturn.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/checkreturn/project.json33
-rw-r--r--tests/src/baseservices/threading/interlocked/common/interlockedhelper_coreclr.cs282
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange1_cti.cs148
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange1_cti.csproj (renamed from tests/src/baseservices/threading/readerwriterlockslim/TryEnterFailureDDBugs124485.csproj)11
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange2.cs361
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange2.csproj (renamed from tests/src/baseservices/threading/readerwriterlockslim/SingleReleaseWriteDDBug71632.csproj)11
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange3.cs167
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange3.csproj47
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange4.cs168
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange4.csproj47
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange5_cti.cs252
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchange5_cti.csproj47
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangedouble.cs120
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangedouble.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.cs98
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeint.cs91
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeint.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.cs87
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.cs101
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchanget.cs57
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchanget.csproj41
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetneg.il95
-rw-r--r--tests/src/baseservices/threading/interlocked/ctorchk/app.config31
-rw-r--r--tests/src/baseservices/threading/interlocked/ctorchk/ctorchk.cs30
-rw-r--r--tests/src/baseservices/threading/interlocked/ctorchk/ctorchk.csproj41
-rw-r--r--tests/src/baseservices/threading/interlocked/ctorchk/project.json33
-rw-r--r--tests/src/baseservices/threading/interlocked/decrement/app.config31
-rw-r--r--tests/src/baseservices/threading/interlocked/decrement/intdec.cs32
-rw-r--r--tests/src/baseservices/threading/interlocked/decrement/intdec.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/decrement/longdec.cs31
-rw-r--r--tests/src/baseservices/threading/interlocked/decrement/longdec.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/decrement/project.json33
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange1_cti.cs165
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange1_cti.csproj47
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange2.cs150
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange2.csproj47
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange3.cs86
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange3.csproj47
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange4.cs86
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange4.csproj47
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange4_cti.cs165
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange4_cti.csproj47
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange5_cti.cs165
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchange5_cti.csproj47
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchangedouble.cs99
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchangedouble.csproj41
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchangefloat.cs107
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchangefloat.csproj41
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchangeobject.cs107
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchangeobject.csproj41
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchanget.cs42
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchanget.csproj41
-rw-r--r--tests/src/baseservices/threading/interlocked/increment/app.config31
-rw-r--r--tests/src/baseservices/threading/interlocked/increment/intinc.cs31
-rw-r--r--tests/src/baseservices/threading/interlocked/increment/intinc.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/increment/longinc.cs31
-rw-r--r--tests/src/baseservices/threading/interlocked/increment/longinc.csproj42
-rw-r--r--tests/src/baseservices/threading/interlocked/increment/project.json33
-rw-r--r--tests/src/baseservices/threading/interlocked/read/app.config31
-rw-r--r--tests/src/baseservices/threading/interlocked/read/interlockedread.cs41
-rw-r--r--tests/src/baseservices/threading/interlocked/read/interlockedread.csproj41
-rw-r--r--tests/src/baseservices/threading/interlocked/read/project.json33
-rw-r--r--tests/src/baseservices/threading/interlocked/read/readthreads.cs97
-rw-r--r--tests/src/baseservices/threading/interlocked/read/readthreads.csproj41
-rw-r--r--tests/src/baseservices/threading/monitor/ctorchk/app.config31
-rw-r--r--tests/src/baseservices/threading/monitor/ctorchk/ctorchk.cs30
-rw-r--r--tests/src/baseservices/threading/monitor/ctorchk/ctorchk.csproj41
-rw-r--r--tests/src/baseservices/threading/monitor/ctorchk/project.json33
-rw-r--r--tests/src/baseservices/threading/monitor/enter/monitorenter.cs501
-rw-r--r--tests/src/baseservices/threading/monitor/enter/monitorenter.csproj41
-rw-r--r--tests/src/baseservices/threading/monitor/isentered/app.config31
-rw-r--r--tests/src/baseservices/threading/monitor/isentered/monitorisentered.cs128
-rw-r--r--tests/src/baseservices/threading/monitor/isentered/monitorisentered.csproj41
-rw-r--r--tests/src/baseservices/threading/monitor/isentered/project.json34
-rw-r--r--tests/src/baseservices/threading/monitor/pulse/monitorpulse02.cs55
-rw-r--r--tests/src/baseservices/threading/monitor/pulse/monitorpulse02.csproj41
-rw-r--r--tests/src/baseservices/threading/monitor/tryenter/app.config31
-rw-r--r--tests/src/baseservices/threading/monitor/tryenter/longtimeout.cs92
-rw-r--r--tests/src/baseservices/threading/monitor/tryenter/longtimeout.csproj41
-rw-r--r--tests/src/baseservices/threading/monitor/tryenter/negativetest.cs104
-rw-r--r--tests/src/baseservices/threading/monitor/tryenter/negativetestharness.csproj41
-rw-r--r--tests/src/baseservices/threading/monitor/tryenter/project.json33
-rw-r--r--tests/src/baseservices/threading/monitor/wait/app.config31
-rw-r--r--tests/src/baseservices/threading/monitor/wait/project.json33
-rw-r--r--tests/src/baseservices/threading/monitor/wait/waitnull.cs26
-rw-r--r--tests/src/baseservices/threading/monitor/wait/waitnull.csproj41
-rw-r--r--tests/src/baseservices/threading/multiinstance/app.config31
-rw-r--r--tests/src/baseservices/threading/multiinstance/multiinstance.cs322
-rw-r--r--tests/src/baseservices/threading/multiinstance/multiinstance.csproj48
-rw-r--r--tests/src/baseservices/threading/multiinstance/project.json33
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am01waitallneg.cs52
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am01waitallneg.csproj41
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am02waitoneneg.cs59
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am02waitoneneg.csproj41
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am04waitany.cs113
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am04waitany.csproj43
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am05waitanymutex.cs112
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am05waitanymutex.csproj43
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am06abandonall.cs70
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am06abandonall.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am07abandonmultiplemutex.cs96
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am07abandonmultiplemutex.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am08mixedarray.cs119
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am08mixedarray.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am09threadabort.cs71
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/am09threadabort.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/app.config31
-rw-r--r--tests/src/baseservices/threading/mutex/abandonedmutex/project.json33
-rw-r--r--tests/src/baseservices/threading/mutex/misc/app.config31
-rw-r--r--tests/src/baseservices/threading/mutex/misc/mutexctor1.cs173
-rw-r--r--tests/src/baseservices/threading/mutex/misc/mutexctor1.csproj47
-rw-r--r--tests/src/baseservices/threading/mutex/misc/mutexctor2.cs104
-rw-r--r--tests/src/baseservices/threading/mutex/misc/mutexctor2.csproj47
-rw-r--r--tests/src/baseservices/threading/mutex/misc/project.json33
-rw-r--r--tests/src/baseservices/threading/mutex/misc/waitone1.cs217
-rw-r--r--tests/src/baseservices/threading/mutex/misc/waitone1.csproj47
-rw-r--r--tests/src/baseservices/threading/mutex/misc/waitone2.cs573
-rw-r--r--tests/src/baseservices/threading/mutex/misc/waitone2.csproj47
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/app.config31
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg1.cs38
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg1.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg2.cs38
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg2.csproj41
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg3.cs38
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg3.csproj41
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg4.cs39
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg4.csproj41
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg5.cs40
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg5.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg6.cs42
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg6.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg7.cs59
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg7.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg8.cs41
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexneg8.csproj41
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexpos1.cs59
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexpos1.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexpos2.cs46
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexpos2.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexpos3.cs48
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexpos3.csproj42
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexpos4.cs85
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/openmutexpos4.csproj41
-rw-r--r--tests/src/baseservices/threading/mutex/openexisting/project.json33
-rw-r--r--tests/src/baseservices/threading/mutex/openmutexcommon.cs32
-rw-r--r--tests/src/baseservices/threading/paramthreadstart/threadstartarray.cs58
-rw-r--r--tests/src/baseservices/threading/paramthreadstart/threadstartarray.csproj41
-rw-r--r--tests/src/baseservices/threading/paramthreadstart/threadstartclass.cs52
-rw-r--r--tests/src/baseservices/threading/paramthreadstart/threadstartclass.csproj41
-rw-r--r--tests/src/baseservices/threading/paramthreadstart/threadstartstruct.cs67
-rw-r--r--tests/src/baseservices/threading/paramthreadstart/threadstartstruct.csproj41
-rw-r--r--tests/src/baseservices/threading/readerwriterlockslim/project.json35
-rw-r--r--tests/src/baseservices/threading/readerwriterlockslim/singlereleasewriteddbug71632.cs159
-rw-r--r--tests/src/baseservices/threading/readerwriterlockslim/tryenterfailureddbugs124485.cs87
-rw-r--r--tests/src/baseservices/threading/readerwriterlockslim/upgrader.cs87
-rw-r--r--tests/src/baseservices/threading/regressions/135972/app.config31
-rw-r--r--tests/src/baseservices/threading/regressions/135972/oswaitinlock.cs70
-rw-r--r--tests/src/baseservices/threading/regressions/135972/oswaitinlock.csproj42
-rw-r--r--tests/src/baseservices/threading/regressions/135972/oswaitinsleep.cs68
-rw-r--r--tests/src/baseservices/threading/regressions/135972/oswaitinsleep.csproj42
-rw-r--r--tests/src/baseservices/threading/regressions/135972/project.json33
-rw-r--r--tests/src/baseservices/threading/regressions/13662/13662-a.cs33
-rw-r--r--tests/src/baseservices/threading/regressions/13662/13662-a.csproj41
-rw-r--r--tests/src/baseservices/threading/regressions/13662/13662-b.cs89
-rw-r--r--tests/src/baseservices/threading/regressions/13662/13662-b.csproj41
-rw-r--r--tests/src/baseservices/threading/regressions/13662/13662-simple.csproj41
-rw-r--r--tests/src/baseservices/threading/regressions/13662/app.config31
-rw-r--r--tests/src/baseservices/threading/regressions/13662/project.json34
-rw-r--r--tests/src/baseservices/threading/regressions/13662/simple.cs33
-rw-r--r--tests/src/baseservices/threading/regressions/269336/app.config31
-rw-r--r--tests/src/baseservices/threading/regressions/269336/objmonhelper.cs37
-rw-r--r--tests/src/baseservices/threading/regressions/269336/objmonhelper.csproj41
-rw-r--r--tests/src/baseservices/threading/regressions/269336/project.json33
-rw-r--r--tests/src/baseservices/threading/regressions/30032/30032.cs40
-rw-r--r--tests/src/baseservices/threading/regressions/30032/30032.csproj41
-rw-r--r--tests/src/baseservices/threading/regressions/30032/app.config31
-rw-r--r--tests/src/baseservices/threading/regressions/30032/project.json34
-rw-r--r--tests/src/baseservices/threading/regressions/beta1/322338.cs111
-rw-r--r--tests/src/baseservices/threading/regressions/beta1/322338.csproj43
-rw-r--r--tests/src/baseservices/threading/regressions/beta1/347011.cs35
-rw-r--r--tests/src/baseservices/threading/regressions/beta1/347011.csproj42
-rw-r--r--tests/src/baseservices/threading/regressions/beta1/app.config31
-rw-r--r--tests/src/baseservices/threading/regressions/beta1/project.json34
-rw-r--r--tests/src/baseservices/threading/regressions/beta2/417296_abort.cs102
-rw-r--r--tests/src/baseservices/threading/regressions/beta2/417296_abort.csproj42
-rw-r--r--tests/src/baseservices/threading/regressions/beta2/437017.cs125
-rw-r--r--tests/src/baseservices/threading/regressions/beta2/437017.csproj41
-rw-r--r--tests/src/baseservices/threading/regressions/beta2/437044.cs119
-rw-r--r--tests/src/baseservices/threading/regressions/beta2/437044.csproj41
-rw-r--r--tests/src/baseservices/threading/regressions/beta2/app.config31
-rw-r--r--tests/src/baseservices/threading/regressions/beta2/project.json34
-rw-r--r--tests/src/baseservices/threading/regressions/devdiv489437/app.config31
-rw-r--r--tests/src/baseservices/threading/regressions/devdiv489437/project.json33
-rw-r--r--tests/src/baseservices/threading/regressions/devdiv489437/test489437.cs52
-rw-r--r--tests/src/baseservices/threading/regressions/devdiv489437/test489437.csproj41
-rw-r--r--tests/src/baseservices/threading/regressions/m2/91848.cs78
-rw-r--r--tests/src/baseservices/threading/regressions/m2/91848.csproj42
-rw-r--r--tests/src/baseservices/threading/regressions/m2/app.config31
-rw-r--r--tests/src/baseservices/threading/regressions/m2/project.json33
-rw-r--r--tests/src/baseservices/threading/regressions/m2/tastaticconst.cs70
-rw-r--r--tests/src/baseservices/threading/regressions/m2/tastaticconst.csproj42
-rw-r--r--tests/src/baseservices/threading/regressions/threadex.cs20
-rw-r--r--tests/src/baseservices/threading/regressions/whidbey_m3/105019.cs57
-rw-r--r--tests/src/baseservices/threading/regressions/whidbey_m3/105019.csproj (renamed from tests/src/baseservices/threading/readerwriterlockslim/Upgrader.csproj)9
-rw-r--r--tests/src/baseservices/threading/regressions/whidbey_m3/200176.cs33
-rw-r--r--tests/src/baseservices/threading/regressions/whidbey_m3/200176.csproj41
-rw-r--r--tests/src/baseservices/threading/regressions/whidbey_m3/app.config31
-rw-r--r--tests/src/baseservices/threading/regressions/whidbey_m3/project.json33
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/app.config31
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/project.json33
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector1.cs69
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector1.csproj42
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector2.cs99
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector2.csproj43
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector3.cs128
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector3.csproj42
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector4.cs97
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector4.csproj43
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector5.cs108
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorector5.csproj43
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg1.cs65
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg1.csproj42
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg2.cs93
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg2.csproj43
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg3.cs103
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg3.csproj42
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg1.cs38
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg1.csproj42
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg2.cs40
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg2.csproj41
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg3.cs38
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg3.csproj41
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg4.cs39
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg4.csproj41
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg5.cs42
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg5.csproj42
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg6.cs42
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg6.csproj42
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.cs43
-rw-r--r--tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.csproj42
-rw-r--r--tests/src/baseservices/threading/semaphore/semaphorecommon.cs36
-rw-r--r--tests/src/baseservices/threading/semaphore/unit/app.config31
-rw-r--r--tests/src/baseservices/threading/semaphore/unit/project.json33
-rw-r--r--tests/src/baseservices/threading/semaphore/unit/semdemo.cs88
-rw-r--r--tests/src/baseservices/threading/semaphore/unit/semdemo.csproj41
-rw-r--r--tests/src/baseservices/threading/semaphore/unit/semtest.cs190
-rw-r--r--tests/src/baseservices/threading/semaphore/unit/semtest.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/app.config31
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandle1.cs63
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandle1.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid.cs41
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid3.cs62
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid3.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4.cs57
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid5.cs63
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid5.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid6.cs78
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid6.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandlenull.cs33
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/bindhandlenull.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/bindhandle/project.json33
-rw-r--r--tests/src/baseservices/threading/threadpool/ctorchk/app.config31
-rw-r--r--tests/src/baseservices/threading/threadpool/ctorchk/ctorchk.cs30
-rw-r--r--tests/src/baseservices/threading/threadpool/ctorchk/ctorchk.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/ctorchk/project.json33
-rw-r--r--tests/src/baseservices/threading/threadpool/unregister/app.config31
-rw-r--r--tests/src/baseservices/threading/threadpool/unregister/project.json33
-rw-r--r--tests/src/baseservices/threading/threadpool/unregister/regression_749068.cs137
-rw-r--r--tests/src/baseservices/threading/threadpool/unregister/regression_749068.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/unregister/unregister01.cs64
-rw-r--r--tests/src/baseservices/threading/threadpool/unregister/unregister01.csproj41
-rw-r--r--tests/src/baseservices/threading/threadpool/unregister/unregister03.cs65
-rw-r--r--tests/src/baseservices/threading/threadpool/unregister/unregister03.csproj41
-rw-r--r--tests/src/baseservices/threading/threadstatic/threadstatic07.cs221
-rw-r--r--tests/src/baseservices/threading/threadstatic/threadstatic07.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/app.config31
-rw-r--r--tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/project.json33
-rw-r--r--tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/threadabort.cs248
-rw-r--r--tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/threadabort.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/misc/app.config31
-rw-r--r--tests/src/baseservices/threading/waithandle/misc/project.json33
-rw-r--r--tests/src/baseservices/threading/waithandle/misc/waithandledispose2.cs100
-rw-r--r--tests/src/baseservices/threading/waithandle/misc/waithandledispose2.csproj47
-rw-r--r--tests/src/baseservices/threading/waithandle/misc/waithandlewaitone1.cs292
-rw-r--r--tests/src/baseservices/threading/waithandle/misc/waithandlewaitone1.csproj47
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/app.config31
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/emptyarray.cs41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/nullarray.cs52
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/nullarraymember.cs41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/nullarraymember.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/project.json33
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallemptyarray.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex1.cs60
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex1.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex10.cs103
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex10.csproj43
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex10a.cs103
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex10a.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex11.cs70
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex11.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex11a.cs70
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex11a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex1a.cs60
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex1a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex2.cs66
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex2.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex2a.cs66
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex2a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex3.cs97
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex3.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex3a.cs97
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex3a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex4.cs87
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex4.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex4a.cs87
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex4a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex5.cs89
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex5.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex5a.cs89
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex5a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex6.cs94
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex6.csproj43
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex6a.cs94
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex6a.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex7.cs76
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex7.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex7a.cs76
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex7a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex8.cs76
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex8.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex8a.cs76
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex8a.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex9.cs100
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex9.csproj43
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex9a.cs100
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallex9a.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitall/waitallnullarray.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/app.config31
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/emptyarray.cs41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/nullarray.cs41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/nullarraymember.cs41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/nullarraymemberwaitany.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/project.json33
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyemptyarray.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex1.cs65
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex1.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex10.cs104
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex10.csproj43
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex10a.cs104
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex10a.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex1a.cs65
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex1a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex2.cs68
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex2.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex2a.cs68
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex2a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex3.cs81
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex3.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex3a.cs81
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex3a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex4.cs76
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex4.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex4a.cs76
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex4a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex5.cs85
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex5.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex5a.cs85
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex5a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex6.cs97
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex6.csproj43
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex6a.cs97
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex6a.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex7.cs69
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex7.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex7a.cs69
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex7a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex8.cs59
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex8.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex8a.cs59
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex8a.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex9.cs102
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex9.csproj43
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex9a.cs102
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanyex9a.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitany/waitanynullarray.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waithandlecommon.cs16
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/app.config31
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/project.json33
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex1.cs58
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex1.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex1a.cs58
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex1a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex2.cs59
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex2.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex2a.cs59
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex2a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex3.cs59
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex3.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex3a.cs59
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex3a.csproj41
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex4.cs57
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex4.csproj42
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex4a.cs57
-rw-r--r--tests/src/baseservices/threading/waithandle/waitone/waitoneex4a.csproj41
422 files changed, 24944 insertions, 483 deletions
diff --git a/tests/src/baseservices/threading/interlocked/add/add.cs b/tests/src/baseservices/threading/interlocked/add/add.cs
new file mode 100644
index 0000000000..52bbb1782d
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/add/add.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class Test
+{
+
+ public static int Main()
+ {
+ int retVal = 100;
+
+ int val = 20;
+ int adder= 5;
+ int foo = Interlocked.Add(ref val, adder);
+ Console.WriteLine("NewValue: " + val);
+ Console.WriteLine("OldValue: " + foo);
+ //if(foo != 20 && val != 25)
+ if ((val != 25) || (foo != val))
+ retVal = -1;
+
+ long val1 = 20;
+ long adder1= 5;
+ long foo1 = Interlocked.Add(ref val1, adder1);
+ Console.WriteLine("NewValue: " + val1);
+ Console.WriteLine("OldValue: " + foo1);
+ //if(foo1 != 20 && val1 != 25)
+ if ((val1 != 25) || (foo1 != val1))
+ retVal = -1;
+
+ if (retVal == 100)
+ Console.WriteLine("Test passed");
+ else
+ Console.WriteLine("Test failed");
+
+ return retVal;
+
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/add/add.csproj b/tests/src/baseservices/threading/interlocked/add/add.csproj
new file mode 100644
index 0000000000..c5b32f3134
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/add/add.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="add.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/add/interlockedaddintwithsubtract.cs b/tests/src/baseservices/threading/interlocked/add/interlockedaddintwithsubtract.cs
new file mode 100644
index 0000000000..b103ec519e
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/add/interlockedaddintwithsubtract.cs
@@ -0,0 +1,107 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+//Regression for DevDiv Bugs 48020
+namespace ExchangeAdd
+{
+ class InterlockedAddInt
+ {
+ static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: InterlockedAddIntWithSubtract " +
+ "/loops:<int> /addVal:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int loops=100;
+ int valueToAdd = 0;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/loops:"))
+ {
+ loops = Convert.ToInt32(args[i].Substring(7));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/addval:"))
+ {
+ valueToAdd = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+ }
+
+ int rValue = 0;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe(loops, valueToAdd);
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorker));
+ threads[i].Start();
+ }
+
+ tsi.Signal();
+
+ for (int i = 0; i < threads.Length; i++)
+ threads[i].Join();
+
+ if (tsi.Total == tsi.Expected * threads.Length)
+ rValue = 100;
+ Console.WriteLine("Expected: " + (tsi.Expected * threads.Length));
+ Console.WriteLine("Actual: " + tsi.Total);
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ ManualResetEvent signal;
+ private int totalValue = 0;
+ private int numberOfIterations;
+ private int valueToAdd;
+ private int valueToSubtract;
+ public ThreadSafe(): this(100,100) { }
+ public ThreadSafe(int loops, int iAdd)
+ {
+ signal = new ManualResetEvent(false);
+ numberOfIterations = loops;
+ valueToAdd = iAdd;
+ valueToSubtract = 0-iAdd;
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+
+ public void ThreadWorker()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < numberOfIterations; i++)
+ {
+ Interlocked.Add(ref totalValue, valueToAdd);
+ Interlocked.Add(ref totalValue, valueToSubtract);
+ }
+
+ }
+ public int Expected
+ {
+ get
+ {
+ return (0);
+ }
+ }
+ public int Total
+ {
+ get { return totalValue; }
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/add/interlockedaddintwithsubtract.csproj b/tests/src/baseservices/threading/interlocked/add/interlockedaddintwithsubtract.csproj
new file mode 100644
index 0000000000..768470f36f
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/add/interlockedaddintwithsubtract.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/loops:500000 /addVal:1</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="InterlockedAddIntWithSubtract.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/readerwriterlockslim/app.config b/tests/src/baseservices/threading/interlocked/checkreturn/app.config
index 62803f5972..c51f616257 100644
--- a/tests/src/baseservices/threading/readerwriterlockslim/app.config
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/app.config
@@ -22,6 +22,10 @@
<assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
</dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
</assemblyBinding>
</runtime>
-</configuration> \ No newline at end of file
+</configuration>
diff --git a/tests/src/baseservices/threading/interlocked/checkreturn/intdeccheckreturn.cs b/tests/src/baseservices/threading/interlocked/checkreturn/intdeccheckreturn.cs
new file mode 100644
index 0000000000..8ef3cd94e5
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/intdeccheckreturn.cs
@@ -0,0 +1,23 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedTest
+{
+ class InterlockTest
+ {
+
+ public static int Main(string[] Args)
+ {
+ int rValue;
+ IntTest testInt = new IntTest(100, 10);
+
+ Console.WriteLine("Check Inc Returnt: {0}", rValue = testInt.CheckDecReturn());
+ Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/checkreturn/intdeccheckreturn.csproj b/tests/src/baseservices/threading/interlocked/checkreturn/intdeccheckreturn.csproj
new file mode 100644
index 0000000000..9a1d524a6f
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/intdeccheckreturn.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="IntDecCheckReturn.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/checkreturn/intinccheckreturn.cs b/tests/src/baseservices/threading/interlocked/checkreturn/intinccheckreturn.cs
new file mode 100644
index 0000000000..6fd08999ea
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/intinccheckreturn.cs
@@ -0,0 +1,23 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedTest
+{
+ class InterlockTest
+ {
+
+ public static int Main(string[] Args)
+ {
+ int rValue;
+ IntTest testInt = new IntTest(100, 10);
+
+ Console.WriteLine("Check Inc Returnt: {0}", rValue = testInt.CheckIncReturn());
+ Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/checkreturn/intinccheckreturn.csproj b/tests/src/baseservices/threading/interlocked/checkreturn/intinccheckreturn.csproj
new file mode 100644
index 0000000000..84fa2afeb5
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/intinccheckreturn.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="IntIncCheckReturn.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/checkreturn/longdeccheckreturn.cs b/tests/src/baseservices/threading/interlocked/checkreturn/longdeccheckreturn.cs
new file mode 100644
index 0000000000..8a39c6a87d
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/longdeccheckreturn.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedTest
+{
+ class InterlockTest
+ {
+ public static int Main(string[] Args)
+ {
+ int rValue;
+ LongTest testLong = new LongTest();
+
+ Console.WriteLine("Check Decrement: {0}", rValue = testLong.CheckDecReturn());
+ Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/checkreturn/longdeccheckreturn.csproj b/tests/src/baseservices/threading/interlocked/checkreturn/longdeccheckreturn.csproj
new file mode 100644
index 0000000000..157d0df814
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/longdeccheckreturn.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="LongDecCheckReturn.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/checkreturn/longinccheckreturn.cs b/tests/src/baseservices/threading/interlocked/checkreturn/longinccheckreturn.cs
new file mode 100644
index 0000000000..1a5a59c15a
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/longinccheckreturn.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedTest
+{
+ class InterlockTest
+ {
+ public static int Main(string[] Args)
+ {
+ int rValue;
+ LongTest testLong = new LongTest();
+
+ Console.WriteLine("Check Decrement: {0}", rValue = testLong.CheckIncReturn());
+ Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/checkreturn/longinccheckreturn.csproj b/tests/src/baseservices/threading/interlocked/checkreturn/longinccheckreturn.csproj
new file mode 100644
index 0000000000..0bcb6fa59c
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/longinccheckreturn.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="LongIncCheckReturn.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/checkreturn/project.json b/tests/src/baseservices/threading/interlocked/checkreturn/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/checkreturn/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/common/interlockedhelper_coreclr.cs b/tests/src/baseservices/threading/interlocked/common/interlockedhelper_coreclr.cs
new file mode 100644
index 0000000000..f9d39a3812
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/common/interlockedhelper_coreclr.cs
@@ -0,0 +1,282 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedTest
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ ///
+ class LongTest
+ {
+ long sharedValue;
+ int iterations;
+ ManualResetEvent signal;
+ Thread[] threads;
+ public LongTest() { }
+ public LongTest(int LoopValue, int NumberOfThreads)
+ {
+ threads = new Thread[NumberOfThreads];
+ iterations = LoopValue;
+ signal = new ManualResetEvent(false);
+ }
+ public int Inc()
+ {
+ sharedValue = 0;
+ long expectedValue = iterations * threads.Length;
+
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(this.SimpleIncrement));
+ threads[i].Start();
+ }
+
+ Thread.Sleep(100);
+ signal.Set();
+ for (int i = 0; i < threads.Length; i++)
+ threads[i].Join();
+ if (sharedValue == expectedValue)
+ return 100;
+
+ return -1;
+ }
+ public int Dec()
+ {
+ sharedValue = iterations * threads.Length;
+
+ int expectedValue = 0;
+
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(this.SimpleDecrement));
+ threads[i].Start();
+ }
+
+ Thread.Sleep(100);
+ signal.Set();
+ for (int i = 0; i < threads.Length; i++)
+ threads[i].Join();
+
+ if (sharedValue == expectedValue)
+ return 100;
+
+ return -1;
+ }
+ private void SimpleIncrement()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < iterations; i++)
+ Interlocked.Increment(ref sharedValue);
+ }
+ private void SimpleDecrement()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < iterations; i++)
+ Interlocked.Decrement(ref sharedValue);
+ }
+ public int CheckIncReturn()
+ {
+ long sharedValue;
+ int rValue = 0;
+
+ foreach (long val in LongVals)
+ {
+ sharedValue = val;
+
+ Console.WriteLine("Test for Inc with value {0}", val);
+ Console.WriteLine("Expected : {0}", val + 1);
+ long returnV = Interlocked.Increment(ref sharedValue);
+ if (val + 1 != returnV )
+ {
+ Console.WriteLine("Failed: Return value is wrong: {0}", returnV);
+ rValue = -1;
+ }
+ if (val + 1 != sharedValue)
+ {
+ Console.WriteLine("Failed: refence value is wrong: {0}", sharedValue);
+ rValue = -2;
+ }
+ }
+
+ if (rValue == 0)
+ rValue = 100;
+
+ return rValue;
+ }
+ public int CheckDecReturn()
+ {
+ long sharedValue;
+ int rValue =0;
+ foreach (long val in LongVals)
+ {
+ sharedValue = val;
+
+ Console.WriteLine("Test for Dec with value {0}", val);
+ Console.WriteLine("Expected : {0}", val - 1);
+ long returnV = Interlocked.Decrement(ref sharedValue);
+ if (val - 1 != returnV)
+ {
+ Console.WriteLine("Failed: Return value is wrong: {0}", returnV);
+ rValue = -1;
+ }
+ if (val -1 != sharedValue)
+ {
+ Console.WriteLine("Failed: refence value is wrong: {0}", sharedValue);
+ rValue = -2;
+ }
+ }
+ if(rValue == 0)
+ rValue = 100;
+ return rValue;
+ }
+ long[] LongVals = new long[5]
+ {
+ Int64.MinValue,
+ Int64.MaxValue,
+ 0,
+ -1,
+ 1
+ };
+ }
+
+
+
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ ///
+ class IntTest
+ {
+ int sharedValue;
+ int iterations;
+ ManualResetEvent signal;
+ Thread[] threads;
+ public IntTest(int LoopValue, int NumberOfThreads)
+ {
+ threads = new Thread[NumberOfThreads];
+ iterations = LoopValue;
+ signal = new ManualResetEvent(false);
+ }
+ public int Inc()
+ {
+ sharedValue = 0;
+
+ int expectedValue = iterations * threads.Length;
+
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(this.SimpleIncrement));
+ threads[i].Start();
+ }
+
+ Thread.Sleep(100);
+ signal.Set();
+ for (int i = 0; i < threads.Length; i++)
+ threads[i].Join();
+
+ if (sharedValue == expectedValue)
+ return 100;
+
+ return -1;
+ }
+ public int Dec()
+ {
+ sharedValue = iterations * threads.Length;
+
+ int expectedValue = 0;
+
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(this.SimpleDecrement));
+ threads[i].Start();
+ }
+
+ Thread.Sleep(100);
+ signal.Set();
+ for (int i = 0; i < threads.Length; i++)
+ threads[i].Join();
+
+ if (sharedValue == expectedValue)
+ return 100;
+
+ return -1;
+ }
+ private void SimpleIncrement()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < iterations; i++)
+ Interlocked.Increment(ref sharedValue);
+ }
+ private void SimpleDecrement()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < iterations; i++)
+ Interlocked.Decrement(ref sharedValue);
+ }
+ public int CheckIncReturn()
+ {
+ int sharedValue;
+ int rValue = 0;
+
+ foreach (int val in IntVals)
+ {
+ sharedValue = val;
+ Console.WriteLine("Test for Inc with value {0}", val);
+ Console.WriteLine("Expected : {0}", val - 1);
+ int returnV = Interlocked.Increment(ref sharedValue);
+ if (val + 1 != returnV )
+ {
+ Console.WriteLine("Failed: Return value is wrong: {0}", returnV);
+ rValue = -1;
+ }
+ if (val + 1 != sharedValue)
+ {
+ Console.WriteLine("Failed: refence value is wrong: {0}", sharedValue);
+ rValue = -2;
+ }
+ }
+
+ if (rValue == 0)
+ rValue = 100;
+
+ return rValue;
+ }
+ public int CheckDecReturn()
+ {
+ int sharedValue;
+ int rValue =0;
+ foreach (int val in IntVals)
+ {
+ sharedValue = val;
+ Console.WriteLine("Test for Dec with value {0}", val);
+ Console.WriteLine("Expected : {0}", val - 1);
+ int returnV = Interlocked.Decrement(ref sharedValue);
+ if (val - 1 != returnV)
+ {
+ Console.WriteLine("Failed: Return value is wrong: {0}", returnV);
+ rValue = -1;
+ }
+ if (val -1 != sharedValue)
+ {
+ Console.WriteLine("Failed: refence value is wrong: {0}", sharedValue);
+ rValue = -2;
+ }
+ }
+ if(rValue == 0)
+ rValue = 100;
+ return rValue;
+ }
+ int[] IntVals = new int[5]
+ {
+ Int32.MinValue,
+ Int32.MaxValue,
+ 0,
+ -1,
+ 1
+ };
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange1_cti.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange1_cti.cs
new file mode 100644
index 0000000000..b7c1da2d76
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange1_cti.cs
@@ -0,0 +1,148 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+/// <summary>
+/// System.Threading.Interlocked.CompareExchange(Double,Double,Double)
+/// </summary>
+///
+
+// This test makes sure that CompareExchange(Double, Double, Double)
+// plays nicely with another thread accessing shared state directly
+public class InterlockedCompareExchange1
+{
+ public static double globalValue = 0.0;
+ public Thread threadA;
+ public Thread threadB;
+ public double state;
+
+
+ #region Public Methods
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ return retVal;
+ }
+
+ #region Positive Test Cases
+ public bool PosTest1()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Using another thread to change the value of variable in this thread");
+
+
+ try
+ {
+ // Spin up two new threads
+ threadA = new Thread(new ThreadStart(TestComChange));
+ threadB = new Thread(new ThreadStart(changeGlobal));
+ // Start Thread A
+ // Thread A runs TestComChange
+ threadA.Start();
+ // Block calling thread until spawned Thread A completes
+ threadA.Join();
+ // Once Thread A completes, block
+ // calling thread until Thread B completes as well
+ threadB.Join();
+ // now, the final value of globalValue and state should be -0.1
+ if (globalValue != -0.1 && state != -0.1)
+ {
+ TestLibrary.TestFramework.LogError("001", "The method did not works, the result is" + globalValue + " " + state);
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+ #endregion
+
+ #region Negetive Test Cases
+ public bool NegTest1()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.BeginScenario("NegTest1: ");
+
+ try
+ {
+
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("101", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+ #endregion
+ #endregion
+
+ public static int Main()
+ {
+ InterlockedCompareExchange1 test = new InterlockedCompareExchange1();
+
+ TestLibrary.TestFramework.BeginTestCase("InterlockedCompareExchange1");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+ public void TestComChange()
+ {
+ // loop 20 times. On the 0-9th times,
+ // only Thread A is accessing globalValue. it keeps
+ // checking if globalValue is 10, which it isn't (it
+ // starts at 0). but, on the 10th time, it starts
+ // Thread B, which at some point runs changeGlobal,
+ // setting globalValue to 10. After Thread B sets
+ // it to 10, the CompareExchange will fire, setting
+ // globalValue to -0.1. Thereafter, CompareExchange
+ // will see that globalValue is not 10, and keep
+ // returning -0.1 to state. each time thru the loop,
+ // Thread A does a sleep(10) so that Thread B has a
+ // chance to do its thing.
+ int i = 0;
+ while (i < 20)
+ {
+ if (i == 10)
+ {
+ threadB.Start();
+ }
+ state = Interlocked.CompareExchange(ref globalValue, -0.1, 10.0);
+ i++;
+ Thread.Sleep(10);
+ }
+ }
+ public void changeGlobal()
+ {
+ // Thread B is the only place this runs
+ // When it runs, it simply sets globalValue to 10.
+ // It should only do this once Thread A tells Thread B
+ // to start.
+ globalValue = 10.0;
+ }
+}
diff --git a/tests/src/baseservices/threading/readerwriterlockslim/TryEnterFailureDDBugs124485.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange1_cti.csproj
index a2d262da9e..a4da143e77 100644
--- a/tests/src/baseservices/threading/readerwriterlockslim/TryEnterFailureDDBugs124485.csproj
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange1_cti.csproj
@@ -13,10 +13,6 @@
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -30,7 +26,7 @@
</ItemGroup>
<ItemGroup>
<!-- Add Compile Object Here -->
- <Compile Include="tryenterfailureddbugs124485.cs" />
+ <Compile Include="CompareExchange1_cti.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
@@ -40,7 +36,10 @@
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange2.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange2.cs
new file mode 100644
index 0000000000..19c307839e
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange2.cs
@@ -0,0 +1,361 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This tests CompareExchange(object, object, object).
+// It just casts a bunch of different value types to object,
+// then makes sure CompareExchange works on those objects.
+public class InterlockedCompareExchange2
+{
+ private const int c_NUM_LOOPS = 100;
+ private const int c_MIN_STRING_LEN = 5;
+ private const int c_MAX_STRING_LEN = 128;
+
+ public static int Main()
+ {
+ InterlockedCompareExchange2 test = new InterlockedCompareExchange2();
+
+ TestLibrary.TestFramework.BeginTestCase("InterlockedCompareExchange2");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+ retVal = PosTest2() && retVal;
+
+ return retVal;
+ }
+
+ // This particular test is for when the comparands are equal and the
+ // switch should take place.
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ object location;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object Interlocked.CompareExchange(object&,object, object) where comparand is equal");
+
+ try
+ {
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Byte");
+ location = (object)TestLibrary.Generator.GetByte();
+ retVal = ExchangeObjects(
+ true,
+ location,
+ location,
+ (object)TestLibrary.Generator.GetByte()
+ ) && retVal;
+ // Note that (&&) performs a logical-AND of
+ // its bool operands, but only evaluates its second
+ // operand if necessary. When ExchangeObjects is first
+ // called (above), retVal (RHS)
+ // is true, as it was initialized above. If ExchangeObjects
+ // returns true, then it checks retVal (RHS), it is also true,
+ // so retVal (LHS) gets set to true. This stays this
+ // way so long as ExchangeObjects returns true in this and
+ // subsequent calls.
+ // If some time ExchangeObjects returns false (0), this
+ // expression does not check retVal (RHS), and instead
+ // retVal (LHS) becomes false. Next call to ExchangeObjects,
+ // retVal (RHS) is false even if ExchangeObjects returns true, so
+ // retVal (both RHS and LHS) remains false for all
+ // subsequent calls to ExchangeObjects. As such, if any one of
+ // the many calls to ExchangeObjects fails, retVal returns false
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Byte[]");
+ byte[] bArr1 = new Byte[5 + (TestLibrary.Generator.GetInt32() % 1024)];
+ byte[] bArr2 = new Byte[5 + (TestLibrary.Generator.GetInt32() % 1024)];
+ TestLibrary.Generator.GetBytes(bArr1);
+ TestLibrary.Generator.GetBytes(bArr2);
+ location = (object)bArr1;
+ retVal = ExchangeObjects(
+ true,
+ location,
+ location,
+ (object)bArr2
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Int16");
+ location = (object)TestLibrary.Generator.GetInt16();
+ retVal = ExchangeObjects(
+ true,
+ location,
+ location,
+ (object)TestLibrary.Generator.GetInt16()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Int32");
+ location = (object)TestLibrary.Generator.GetInt32();
+ retVal = ExchangeObjects(
+ true,
+ location,
+ location,
+ (object)TestLibrary.Generator.GetInt32()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Int64");
+ location = (object)(object)TestLibrary.Generator.GetInt64();
+ retVal = ExchangeObjects(
+ true,
+ location,
+ location,
+ (object)TestLibrary.Generator.GetInt64()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Single");
+ location = (object)(object)TestLibrary.Generator.GetSingle();
+ retVal = ExchangeObjects(
+ true,
+ location,
+ location,
+ (object)TestLibrary.Generator.GetSingle()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Double");
+ location = (object)(object)TestLibrary.Generator.GetDouble();
+ retVal = ExchangeObjects(
+ true,
+ location,
+ location,
+ (object)TestLibrary.Generator.GetDouble()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == string");
+ location = TestLibrary.Generator.GetString(false, c_MIN_STRING_LEN, c_MAX_STRING_LEN);
+ retVal = ExchangeObjects(
+ true,
+ location,
+ location,
+ (object)TestLibrary.Generator.GetString(false, c_MIN_STRING_LEN, c_MAX_STRING_LEN)
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == char");
+ location = TestLibrary.Generator.GetChar();
+ retVal = ExchangeObjects(
+ true,
+ location,
+ location,
+ (object)TestLibrary.Generator.GetChar()
+ ) && retVal;
+
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ // This particular test is for when the comparands are not equal and the
+ // switch should not take place.
+ public bool PosTest2()
+ {
+ bool retVal = true;
+ object location;
+ object other;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: object Interlocked.CompareExchange(object&,object, object) where comparand are not equal");
+
+ try
+ {
+ TestLibrary.TestFramework.BeginScenario("PosTest2: object == Byte");
+ location = (object)TestLibrary.Generator.GetByte();
+ other = (object)TestLibrary.Generator.GetByte();
+
+ retVal = ExchangeObjects(
+ false,
+ location,
+ (object)((byte)location+1),
+ other
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: object == Byte[]");
+ byte[] bArr1 = new Byte[5 + (TestLibrary.Generator.GetInt32() % 1024)];
+ byte[] bArr2 = new Byte[5 + (TestLibrary.Generator.GetInt32() % 1024)];
+ byte[] bArr3 = new Byte[5 + (TestLibrary.Generator.GetInt32() % 1024)];
+ TestLibrary.Generator.GetBytes(bArr1);
+ TestLibrary.Generator.GetBytes(bArr2);
+ TestLibrary.Generator.GetBytes(bArr3);
+ location = (object)bArr1;
+ retVal = ExchangeObjects(
+ false,
+ location,
+ (object)bArr2,
+ (object)bArr3
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: object == Int16");
+ location = (object)TestLibrary.Generator.GetInt16();
+ other = (object)TestLibrary.Generator.GetInt16();
+
+ retVal = ExchangeObjects(
+ false,
+ location,
+ (object)((Int16)location+1),
+ other
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: object == Int32");
+ location = (object)TestLibrary.Generator.GetInt32();
+ other = (object)TestLibrary.Generator.GetInt32();
+
+ retVal = ExchangeObjects(
+ false,
+ location,
+ (object)((Int32)location+1),
+ other
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: object == Int64");
+ location = (object)(object)TestLibrary.Generator.GetInt64();
+ other = (object)TestLibrary.Generator.GetInt64();
+
+ retVal = ExchangeObjects(
+ false,
+ location,
+ (object)((Int64)location+1),
+ other
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: object == Single");
+ location = (object)(object)TestLibrary.Generator.GetSingle();
+ other = (object)TestLibrary.Generator.GetSingle();
+
+ retVal = ExchangeObjects(
+ false,
+ location,
+ (object)((Single)location+1),
+ other
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: object == Double");
+ location = (object)(object)TestLibrary.Generator.GetDouble();
+ other = (object)TestLibrary.Generator.GetDouble();
+
+ retVal = ExchangeObjects(
+ false,
+ location,
+ (object)((Double)location+1),
+ other
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == string");
+ location = TestLibrary.Generator.GetString(false, c_MIN_STRING_LEN, c_MAX_STRING_LEN);
+ retVal = ExchangeObjects(
+ false,
+ location,
+ (string)location+TestLibrary.Generator.GetChar(),
+ (object)TestLibrary.Generator.GetDouble()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == char");
+ location = TestLibrary.Generator.GetChar();
+ object comparand;
+ do
+ {
+ comparand = TestLibrary.Generator.GetChar();
+ }
+ while(comparand == location);
+ retVal = ExchangeObjects(
+ false,
+ location,
+ comparand,
+ (object)TestLibrary.Generator.GetChar()
+ ) && retVal;
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ public bool ExchangeObjects(bool exchange, object location, object comparand, object value)
+ {
+ bool retVal = true;
+ object oldLocation;
+ object originalLocation = location;
+
+ if (!exchange && comparand == location)
+ {
+ TestLibrary.TestFramework.LogError("003", "Comparand and location are equal unexpectadly!!!!");
+ retVal = false;
+ }
+ if (exchange && comparand != location)
+ {
+ TestLibrary.TestFramework.LogError("004", "Comparand and location are not equal unexpectadly!!!!");
+ retVal = false;
+ }
+
+ // this is the only significant difference between this test
+ // and InterlockedCompareExchange7.cs - here we use the
+ // object overload directly.
+ oldLocation = Interlocked.CompareExchange(ref location, value, comparand);
+
+ // if exchange=true, then the exchange was supposed to take place.
+ // as a result, assuming value did not equal comparand initially,
+ // and location did equal comparand initially, then we should
+ // expect the following:
+ // oldLoc holds locations old value,oldLocation == comparand, because oldLocation equals what
+ // location equaled before the exchange, and that
+ // equaled comparand
+ // location == value, because the exchange took place
+
+ if (exchange)
+ {
+ if (!Object.ReferenceEquals(location,value))
+ {
+ TestLibrary.TestFramework.LogError("005", "Interlocked.CompareExchange() did not do the exchange correctly: Expected location(" + location + ") to equal value(" + value + ")");
+ retVal = false;
+ }
+ if (!Object.ReferenceEquals(oldLocation,originalLocation))
+ {
+ TestLibrary.TestFramework.LogError("006", "Interlocked.CompareExchange() did not return the expected value: Expected oldLocation(" + oldLocation + ") to equal originalLocation(" + originalLocation + ")");
+ retVal = false;
+ }
+ }
+ // if exchange!=true, then the exchange was supposed to NOT take place.
+ // expect the following:
+ // location == originalLocation, because the exchange did not happen
+ // oldLocation == originalLocation, because the exchange did not happen
+ else
+ {
+ if (!Object.ReferenceEquals(location,originalLocation))
+ {
+ TestLibrary.TestFramework.LogError("007", "Interlocked.CompareExchange() should not change the location: Expected location(" + location + ") to equal originalLocation(" + originalLocation + ")");
+ retVal = false;
+ }
+ if (!Object.ReferenceEquals(oldLocation,originalLocation))
+ {
+ TestLibrary.TestFramework.LogError("008", "Interlocked.CompareExchange() did not return the expected value: Expected oldLocation(" + oldLocation + ") to equal originalLocation(" + originalLocation + ")");
+ retVal = false;
+ }
+ }
+
+ return retVal;
+ }
+
+}
diff --git a/tests/src/baseservices/threading/readerwriterlockslim/SingleReleaseWriteDDBug71632.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange2.csproj
index f70117f419..6679e75527 100644
--- a/tests/src/baseservices/threading/readerwriterlockslim/SingleReleaseWriteDDBug71632.csproj
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange2.csproj
@@ -13,10 +13,6 @@
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -30,7 +26,7 @@
</ItemGroup>
<ItemGroup>
<!-- Add Compile Object Here -->
- <Compile Include="singlereleasewriteddbug71632.cs" />
+ <Compile Include="CompareExchange2.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
@@ -40,7 +36,10 @@
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange3.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange3.cs
new file mode 100644
index 0000000000..5b8fb96f26
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange3.cs
@@ -0,0 +1,167 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// Tests that CompareExchange(Double, Double, Double)
+// actually switches values when location = comparand and
+// does not when it does not
+public class InterlockedCompareExchange3
+{
+ private const int c_NUM_LOOPS = 100;
+
+ public static int Main()
+ {
+ InterlockedCompareExchange3 test = new InterlockedCompareExchange3();
+
+ TestLibrary.TestFramework.BeginTestCase("InterlockedCompareExchange3");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+ retVal = PosTest2() && retVal;
+
+ return retVal;
+ }
+
+ // This test iterates 100 times. Each time it gets two
+ // Doubles, value and location. It stores location in comparand, so
+ // they will be equal on comparison. It then uses
+ // Interlocked.CompareExchange to compare location with comparand.
+ // Since they are equal, it must exchange: location is replaced by
+ // value, and the original value in location is returned to oldLocation.
+ // Then it checks that location now equals value, and that oldLocation
+ // equals comparand. If either of these are not true, retVal gets set to
+ // false, and ultimately it returns false. since location is never null,
+ // it should not throw an exception, so doing so causes the test
+ // to fail.
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ Double location;
+ Double value;
+ Double comparand;
+ Double oldLocation;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Double Interlocked.CompareExchange(Double&,Double,Double) where comparand is equal");
+
+ try
+ {
+ for (int i=0; i<c_NUM_LOOPS; i++)
+ {
+ value = TestLibrary.Generator.GetDouble();
+ location = TestLibrary.Generator.GetDouble();
+ comparand = location;
+
+ oldLocation = Interlocked.CompareExchange(ref location, value, comparand);
+ // At this point, we should be able to make
+ // the following assertion:
+ // location = value
+ // oldLocation = comparand
+
+ if (!location.Equals(value))
+ {
+ TestLibrary.TestFramework.LogError("001", "Interlocked.CompareExchange() did not do the exchange correctly: Expected(" + value + ") Actual(" + location + ")");
+ retVal = false;
+ }
+
+ if (!oldLocation.Equals(comparand))
+ {
+ TestLibrary.TestFramework.LogError("002", "Interlocked.CompareExchange() did not return the expected value: Expected(" + comparand + ") Actual(" + oldLocation + ")");
+ retVal = false;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ // since location is not null, any exception
+ // causes test failure.
+ TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ // This test iterates 100 times. Each time it gets two
+ // Doubles, value and location. It then gets a value for comparand, such
+ // that it is NOT EQUAL to location. It then uses
+ // Interlocked.CompareExchange to compare location with comparand.
+ // Since they are not equal, it does not exchange.
+ // since location is never null,
+ // it should not throw an exception, so doing so causes the test
+ // to fail.
+ public bool PosTest2()
+ {
+ bool retVal = true;
+ Double location;
+ Double value;
+ Double comparand;
+ Double oldLocation;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: Double Interlocked.CompareExchange(Double&,Double,Double) where comparand are not equal");
+
+ try
+ {
+ for (int i=0; i<c_NUM_LOOPS; i++)
+ {
+ value = TestLibrary.Generator.GetDouble();
+ location = TestLibrary.Generator.GetDouble();
+ comparand = value;
+ while(comparand.Equals(location))
+ {
+ comparand = TestLibrary.Generator.GetDouble();
+ }
+
+ oldLocation = Interlocked.CompareExchange(ref location, value, comparand);
+ // At this point, we should be able to make
+ // the following assertions:
+ // location != value
+ // location != comparand
+ // location = oldLocation
+ // oldLocation != comparand
+
+ if (location.Equals(value))
+ {
+ TestLibrary.TestFramework.LogError("004", "Interlocked.CompareExchange() did not do the exchange correctly: Expected(" + value + ") Actual(" + location + ")");
+ retVal = false;
+ }
+
+ if (oldLocation.Equals(comparand))
+ {
+ TestLibrary.TestFramework.LogError("005", "Interlocked.CompareExchange() did not return the expected value: Expected(" + location + ") Actual(" + oldLocation + ")");
+ retVal = false;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ // since location is not null, any exception
+ // causes test failure.
+ TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+}
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange3.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange3.csproj
new file mode 100644
index 0000000000..6852030b60
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange3.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="CompareExchange3.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange4.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange4.cs
new file mode 100644
index 0000000000..a777b6fba9
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange4.cs
@@ -0,0 +1,168 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// Tests that CompareExchange(Single, Single, Single)
+// a.k.a., CompareExchange(float, float, float)
+// actually switches values when location = comparand and
+// does not when it does not
+public class InterlockedCompareExchange4
+{
+ private const int c_NUM_LOOPS = 100;
+
+ public static int Main()
+ {
+ InterlockedCompareExchange4 test = new InterlockedCompareExchange4();
+
+ TestLibrary.TestFramework.BeginTestCase("InterlockedCompareExchange4");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+ retVal = PosTest2() && retVal;
+
+ return retVal;
+ }
+
+ // This test iterates 100 times. Each time it gets two
+ // Singles, value and location. It stores location in comparand, so
+ // they will be equal on comparison. It then uses
+ // Interlocked.CompareExchange to compare location with comparand.
+ // Since they are equal, it must exchange: location is replaced by
+ // value, and the original value in location is returned to oldLocation.
+ // Then it checks that location now equals value, and that oldLocation
+ // equals comparand. If either of these are not true, retVal gets set to
+ // false, and ultimately it returns false. since location is never null,
+ // it should not throw an exception, so doing so causes the test
+ // to fail.
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ Single location;
+ Single value;
+ Single comparand;
+ Single oldLocation;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Single Interlocked.CompareExchange(Single&,Single,Single) where comparand is equal");
+
+ try
+ {
+ for (int i=0; i<c_NUM_LOOPS; i++)
+ {
+ value = TestLibrary.Generator.GetSingle();
+ location = TestLibrary.Generator.GetSingle();
+ comparand = location;
+
+ oldLocation = Interlocked.CompareExchange(ref location, value, comparand);
+ // At this point, we should be able to make
+ // the following assertion:
+ // location = value
+ // oldLocation = comparand
+
+ if (!location.Equals(value))
+ {
+ TestLibrary.TestFramework.LogError("001", "Interlocked.CompareExchange() did not do the exchange correctly: Expected(" + value + ") Actual(" + location + ")");
+ retVal = false;
+ }
+
+ if (!oldLocation.Equals(comparand))
+ {
+ TestLibrary.TestFramework.LogError("002", "Interlocked.CompareExchange() did not return the expected value: Expected(" + comparand + ") Actual(" + oldLocation + ")");
+ retVal = false;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ // since location is not null, any exception
+ // causes test failure.
+ TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ // This test iterates 100 times. Each time it gets two
+ // Singles, value and location. It then gets a value for comparand, such
+ // that it is NOT EQUAL to location. It then uses
+ // Interlocked.CompareExchange to compare location with comparand.
+ // Since they are not equal, it does not exchange.
+ // since location is never null,
+ // it should not throw an exception, so doing so causes the test
+ // to fail.
+ public bool PosTest2()
+ {
+ bool retVal = true;
+ Single location;
+ Single value;
+ Single comparand;
+ Single oldLocation;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: Single Interlocked.CompareExchange(Single&,Single,Single) where comparand are not equal");
+
+ try
+ {
+ for (int i=0; i<c_NUM_LOOPS; i++)
+ {
+ value = TestLibrary.Generator.GetSingle();
+ location = TestLibrary.Generator.GetSingle();
+ comparand = value;
+ while(comparand.Equals(location))
+ {
+ comparand = TestLibrary.Generator.GetSingle();
+ }
+
+ oldLocation = Interlocked.CompareExchange(ref location, value, comparand);
+ // At this point, we should be able to make
+ // the following assertions:
+ // location != value
+ // location != comparand
+ // location = oldLocation
+ // oldLocation != comparand
+
+ if (location.Equals(value))
+ {
+ TestLibrary.TestFramework.LogError("004", "Interlocked.CompareExchange() did not do the exchange correctly: Expected(" + value + ") Actual(" + location + ")");
+ retVal = false;
+ }
+
+ if (oldLocation.Equals(comparand))
+ {
+ TestLibrary.TestFramework.LogError("005", "Interlocked.CompareExchange() did not return the expected value: Expected(" + comparand + ") Actual(" + oldLocation + ")");
+ retVal = false;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ // since location is not null, any exception
+ // causes test failure.
+ TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+}
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange4.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange4.csproj
new file mode 100644
index 0000000000..86fee1ff1a
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange4.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="CompareExchange4.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange5_cti.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange5_cti.cs
new file mode 100644
index 0000000000..f703ab948b
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange5_cti.cs
@@ -0,0 +1,252 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+/// <summary>
+/// System.Threading.Interlocked.CompareExchange(ref object,object,object)
+/// </summary>
+
+// Tests that CompareExchange(object, object, object)
+// plays nicely with another thread accessing shared state directly
+// Also includes a test for when location = comparand = null (should
+// switch).
+public class InterlockedCompareExchange5
+{
+ public static object globalValue;
+ public Thread threadA;
+ public Thread threadB;
+ public object state;
+ public myClass obMyClass;
+
+ #region Public Methods
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+ retVal = PosTest2() && retVal;
+ retVal = PosTest3() && retVal;
+
+ return retVal;
+ }
+
+ #region Positive Test Cases
+ public bool PosTest1()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: The object is a string");
+
+ try
+ {
+ // Spin up two new threads
+ threadA = new Thread(new ThreadStart(TestComChange));
+ threadB = new Thread(new ThreadStart(changeGlobal));
+ // Start Thread A
+ // Thread A runs TestComChange
+ threadA.Start();
+ // Block spawning thread until Thread A completes
+ threadA.Join();
+ // Once Thread A completes, block spawning thread
+ // until Thread B completes as well
+ threadB.Join();
+ // now, the final values of
+ // globalValue and state should be "changedValue"
+ if (globalValue.ToString() != "changedValue" && state != (object)("changedValue"))
+ {
+ TestLibrary.TestFramework.LogError("001", "The method did not works, the result is" + globalValue + " " + state);
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest2()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: The object is a custom class");
+
+ obMyClass = new myClass(123456789);
+ try
+ {
+ // Spin up two new threads
+ threadA = new Thread(new ThreadStart(TestComChange2));
+ threadB = new Thread(new ThreadStart(changeGlobal2));
+ // Start Thread A
+ // Thread A runs TestComChange2
+ threadA.Start();
+ // Block spawning thread until Thread A completes
+ threadA.Join();
+ // Once Thread A completes, block spawning thread
+ // until Thread B completes as well
+ threadB.Join();
+ // now, the final values of
+ // globalValue and state should NOT be -100
+ if (((myClass)globalValue).a != -100 && ((myClass)state).a != -100)
+ {
+ TestLibrary.TestFramework.LogError("003", "The method did not works, the result is" + globalValue + " " + state);
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest3()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest3: The first argument is a null reference");
+
+ try
+ {
+ // a non-null object
+ object value = new myClass(-100);
+ // a null object
+ object comparand = null;
+ // a null initial state
+ globalValue = null;
+ // globalValue is null, so it should switch
+ // and return null
+ // this is a major difference with
+ // InterlockedCompareExchange8.cs --
+ // here we use the object overload
+ state = Interlocked.CompareExchange(ref globalValue, value, comparand);
+ // globalValue should equal value now
+ if (globalValue != value)
+ {
+ TestLibrary.TestFramework.LogError("005", "The method did not works, the result is" + globalValue + " " + state);
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+ #endregion
+ #region Negative Test Cases
+ #endregion
+ #endregion
+
+ public static int Main()
+ {
+ InterlockedCompareExchange5 test = new InterlockedCompareExchange5();
+
+ TestLibrary.TestFramework.BeginTestCase("InterlockedCompareExchange5");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+ public void TestComChange()
+ {
+ // set a value
+ object value = "changedValue";
+ // set a different value
+ object comparand = "comparand";
+ int i = 0;
+ // loop 20 times
+ while (i < 20)
+ {
+ // first ten times, we just skip this
+ // then on the tenth time, fire Thread B,
+ // setting globalValue to "Comparand"
+ if (i == 10)
+ {
+ threadB.Start();
+ }
+ // first ten iterations, globalValue does not
+ // equal comparand, so it keeps returning
+ // the contents of globalValue without
+ // poking value into it
+ // after ten, Thread B kicks in, and
+ // it matches, subsequently, globalValue
+ // gets set to "changedValue"
+ // this is a major difference with
+ // InterlockedCompareExchange8.cs --
+ // here we use the object overload
+ state = Interlocked.CompareExchange(ref globalValue, value, comparand);
+ i++;
+ Thread.Sleep(10);
+ }
+ }
+ public void changeGlobal()
+ {
+ // set when B runs
+ globalValue = "comparand";
+ }
+
+ public void TestComChange2()
+ {
+ // set a value
+ object value = new myClass(-100);
+ // set a different value
+ object comparand = obMyClass;
+ int i = 0;
+ // loop 20 times
+ while (i < 20)
+ {
+ // first ten times, we just skip this
+ // then on the tenth time, fire Thread B,
+ // setting globalValue to obMyClass
+ if (i == 10)
+ {
+ threadB.Start();
+ }
+ // first ten iterations, globalValue does not
+ // equal comparand, so it keeps returning
+ // the contents of globalValue without
+ // poking value into it
+ // after ten, Thread B kicks in, and
+ // it matches, subsequently, globalValue
+ // gets set to point to where value does
+ // this is a major difference with
+ // InterlockedCompareExchange8.cs --
+ // here we use the object overload
+ state = Interlocked.CompareExchange(ref globalValue, value, comparand);
+ i++;
+ Thread.Sleep(10);
+ }
+ }
+ public void changeGlobal2()
+ {
+ globalValue = obMyClass;
+ }
+}
+public class myClass
+{
+ public int a;
+ public myClass(int value)
+ {
+ a = value;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange5_cti.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange5_cti.csproj
new file mode 100644
index 0000000000..3ff26523a4
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchange5_cti.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="CompareExchange5_cti.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangedouble.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangedouble.cs
new file mode 100644
index 0000000000..02fffd9862
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangedouble.cs
@@ -0,0 +1,120 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Globalization;
+
+namespace CompareExchangeDouble
+{
+ class CompareExchangeDouble
+ {
+ static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: CompareExchangeDouble " +
+ "/loops:<int> /addVal:<double>");
+ return -1;
+ }
+
+ // Get the args
+ int loops=100;
+ double valueToAdd = 1E+100;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/loops:"))
+ {
+ loops = Convert.ToInt32(args[i].Substring(7));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/addval:"))
+ {
+ CultureInfo myCultureInfo = new CultureInfo("en-US");
+ valueToAdd = Double.Parse(args[i].Substring(8), myCultureInfo);
+ continue;
+ }
+ }
+
+ int rValue = 0;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe(loops,valueToAdd);
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorker));
+ threads[i].Start();
+ }
+
+ tsi.Signal();
+
+ for(int i=0;i<threads.Length;i++)
+ threads[i].Join();
+ double expected = 0.0D;
+ for(int i=0;i<threads.Length*loops;i++)
+ expected = (double)(expected + valueToAdd);
+ if(tsi.Total == expected)
+ rValue = 100;
+ Console.WriteLine("Expected: "+expected);
+ Console.WriteLine("Actual : "+tsi.Total);
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ ManualResetEvent signal;
+ private double totalValue = 0D;
+ private int numberOfIterations;
+ private double valueToAdd;
+ public ThreadSafe(): this(100,1E+100) { }
+ public ThreadSafe(int loops, double addend)
+ {
+ signal = new ManualResetEvent(false);
+ numberOfIterations = loops;
+ valueToAdd = addend;
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+
+ public void ThreadWorker()
+ {
+ signal.WaitOne();
+ for(int i=0;i<numberOfIterations;i++)
+ AddToTotal(valueToAdd);
+ }
+
+ public double Expected
+ {
+ get
+ {
+ return (numberOfIterations * valueToAdd);
+ }
+ }
+
+ public double Total
+ {
+ get { return totalValue; }
+ }
+
+ private double AddToTotal(double addend)
+ {
+ double initialValue, computedValue;
+ do
+ {
+ initialValue = totalValue;
+ computedValue = (double)(initialValue + addend);
+ }
+ while (initialValue != Interlocked.CompareExchange(
+ ref totalValue, computedValue, initialValue));
+ return computedValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangedouble.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangedouble.csproj
new file mode 100644
index 0000000000..78b25a31b3
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangedouble.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/loops:100 /addVal:1.79769313486232E+304</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="CompareExchangeDouble.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.cs
new file mode 100644
index 0000000000..9ffe170ec2
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.cs
@@ -0,0 +1,98 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace Exchange
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ class Class1
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static int Main(string[] args)
+ {
+ int loops = 100;
+ int rValue = 0;
+ if(args.Length == 1)
+ loops = Int32.Parse(args[0]);
+ float valuetoadd = 10.12345F;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe(100,valuetoadd);
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorker));
+ threads[i].Start();
+ }
+
+ tsi.Signal();
+
+ for(int i=0;i<threads.Length;i++)
+ threads[i].Join();
+ float expected = 0.0F;
+ for(int i=0;i<threads.Length*loops;i++)
+ expected = (float)(expected + valuetoadd);
+ if(tsi.Total == expected)
+ rValue = 100;
+ Console.WriteLine("Expected: "+expected);
+ Console.WriteLine("Actual : "+tsi.Total);
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ ManualResetEvent signal;
+ private float totalValue = 0F;
+ private int numberOfIterations;
+ private float valueToAdd;
+ public ThreadSafe(): this(100,10.12345F) { }
+ public ThreadSafe(int loops, float addend)
+ {
+ signal = new ManualResetEvent(false);
+ numberOfIterations = loops;
+ valueToAdd = addend;
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+
+ public void ThreadWorker()
+ {
+ signal.WaitOne();
+ for(int i=0;i<numberOfIterations;i++)
+ AddToTotal(valueToAdd);
+
+ }
+ public float Expected
+ {
+ get
+ {
+ return (numberOfIterations * valueToAdd);
+ }
+ }
+ public float Total
+ {
+ get { return totalValue; }
+ }
+ private float AddToTotal(float addend)
+ {
+ float initialValue, computedValue;
+ do
+ {
+ initialValue = totalValue;
+ computedValue = (float)(initialValue + addend);
+ } while (initialValue != Interlocked.CompareExchange(ref totalValue, computedValue, initialValue));
+ return computedValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.csproj
new file mode 100644
index 0000000000..f4e79ff877
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="CompareExchangeFloat.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeint.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeint.cs
new file mode 100644
index 0000000000..d66fd51240
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeint.cs
@@ -0,0 +1,91 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace Exchange
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ class Class1
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+
+ static int Main(string[] args)
+ {
+ int rValue = 0;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe();
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorker));
+ threads[i].Start();
+ }
+
+ tsi.Signal();
+
+ for(int i=0;i<threads.Length;i++)
+ threads[i].Join();
+
+ if(tsi.Total == tsi.Expected * threads.Length)
+ rValue = 100;
+ Console.WriteLine("Test Expected {0}, but found {1}", tsi.Expected * threads.Length, tsi.Total);
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ ManualResetEvent signal;
+ private int totalValue = 0;
+ private int numberOfIterations;
+ private int valueToAdd;
+ public ThreadSafe(): this(100,100) { }
+ public ThreadSafe(int loops, int addend)
+ {
+ signal = new ManualResetEvent(false);
+ numberOfIterations = loops;
+ valueToAdd = addend;
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+
+ public void ThreadWorker()
+ {
+ signal.WaitOne();
+ for(int i=0;i<numberOfIterations;i++)
+ AddToTotal(valueToAdd);
+
+ }
+ public int Expected
+ {
+ get
+ {
+ return (numberOfIterations * valueToAdd);
+ }
+ }
+ public int Total
+ {
+ get { return totalValue; }
+ }
+ private int AddToTotal(int addend)
+ {
+ int initialValue, computedValue;
+ do
+ {
+ initialValue = totalValue;
+ computedValue = initialValue + addend;
+ } while (initialValue != Interlocked.CompareExchange(ref totalValue, computedValue, initialValue));
+ return computedValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeint.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeint.csproj
new file mode 100644
index 0000000000..02750e3611
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeint.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="CompareExchangeInt.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.cs
new file mode 100644
index 0000000000..9010b3e762
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.cs
@@ -0,0 +1,87 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Collections;
+
+namespace Exchange
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ class Class1
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static int Main(string[] args)
+ {
+ int rValue = 0;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe(threads.Length);
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(tsi.ChangeValue));
+ threads[i].Name = i.ToString();
+ threads[i].Start();
+ }
+
+ tsi.Signal();
+
+ for(int i=0;i<threads.Length;i++)
+ threads[i].Join();
+
+ if(tsi.Success)
+ rValue = 100;
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ private int threadCount;
+ ManualResetEvent signal;
+ private IntPtr mValue;
+ private int accessCount;
+ private static object myLock = new Object();
+
+ public ThreadSafe(int size)
+ {
+ threadCount = size;
+ mValue = IntPtr.Zero;
+ signal = new ManualResetEvent(false);
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+ public bool Success
+ {
+ get {
+ Console.WriteLine("AccessCount {0} should equal threadCount {1}", accessCount, threadCount);
+ Console.WriteLine("mValue.ToInt32 {0} should equal threadCount {1}", mValue.ToInt32(), threadCount);
+ return (accessCount == threadCount) && (mValue.ToInt32() == threadCount);
+ }
+ }
+ public void ChangeValue()
+ {
+ IntPtr initialValue, newValue;
+
+ signal.WaitOne();
+ do
+ {
+ initialValue = mValue;
+ lock (myLock)
+ {
+ newValue = new IntPtr(mValue.ToInt32() + 1);
+ }
+ } while (initialValue != Interlocked.CompareExchange(ref mValue, newValue, initialValue));
+ Interlocked.Increment(ref accessCount);
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.csproj
new file mode 100644
index 0000000000..659c063121
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="CompareExchangeIntPtr.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.cs
new file mode 100644
index 0000000000..f135e156fb
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.cs
@@ -0,0 +1,101 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Collections;
+
+namespace Exchange
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ class Class1
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static int Main(string[] args)
+ {
+ int rValue = 0;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe(threads.Length);
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(tsi.ChangeValue));
+ threads[i].Name = i.ToString();
+ threads[i].Start();
+ }
+
+ tsi.Signal();
+
+ for(int i=0;i<threads.Length;i++)
+ threads[i].Join();
+
+ if(tsi.Success)
+ rValue = 100;
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ ArrayList myObjArray;
+ ArrayList postObjArray;
+ ManualResetEvent signal;
+ private Object mValue;
+ private int accessCount;
+ public ThreadSafe(int arraySize)
+ {
+ accessCount = 0;
+ mValue = null;
+ postObjArray = new ArrayList(arraySize + 1);
+ myObjArray = new ArrayList(arraySize+1);
+ for(int i=0;i<arraySize;i++)
+ myObjArray.Add(new Object());
+ signal = new ManualResetEvent(false);
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+ public bool Success
+ {
+ get
+ {
+ for (int i = 0; i < postObjArray.Count; i++)
+ for (int j = i+1; j < postObjArray.Count; j++)
+ if (postObjArray[i] == postObjArray[j])
+ {
+ Console.WriteLine("Failure!!!!");
+ Console.WriteLine("ValueOne:" + postObjArray[i]);
+ Console.WriteLine("ValueTwo:" + postObjArray[j]);
+ Console.WriteLine("Position:" + i + " " + j);
+ return false;
+ }
+ //No dups so check for proper count
+ Console.WriteLine("Expect accessCount {0} to equal postObjArray.Count {1}", accessCount, postObjArray.Count);
+ return (accessCount == (postObjArray.Count));
+ }
+ }
+ public void ChangeValue()
+ {
+ Object initialValue, newValue;
+ signal.WaitOne();
+ do
+ {
+ initialValue = mValue;
+ newValue = myObjArray[Int32.Parse(Thread.CurrentThread.Name)];
+ } while (initialValue != Interlocked.CompareExchange(ref mValue, newValue, initialValue));
+ lock (this)
+ {
+ postObjArray.Add(initialValue);
+ }
+ Interlocked.Increment(ref accessCount);
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.csproj
new file mode 100644
index 0000000000..58898e213b
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="CompareExchangeObject.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchanget.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchanget.cs
new file mode 100644
index 0000000000..15c230f15a
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchanget.cs
@@ -0,0 +1,57 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class Test
+{
+
+ public static int Main()
+ {
+ Console.WriteLine("Start");
+ int retVal = 100;
+ string STORAGE = "OLD";
+ string NOW = "NOW";
+ string ret = "";
+
+ Console.WriteLine("ref loc: " + STORAGE);
+ Console.WriteLine("Return: " + ret);
+ Console.WriteLine("Comparand:" + STORAGE);
+ Console.WriteLine("Attempting Exchange in:" + NOW);
+
+ string OLDSTORAGE = STORAGE;
+ ret = Interlocked.CompareExchange<string>(ref STORAGE,NOW,STORAGE);
+
+ Console.WriteLine("ref loc: " + STORAGE);
+ Console.WriteLine("Return: " + ret);
+
+ //if(ret == "" || STORAGE != NOW)
+ if(ret != OLDSTORAGE || STORAGE != NOW)
+ retVal = -1;
+
+ Console.WriteLine(100 == retVal ? "Test Passed":"Test Failed");
+
+
+ STORAGE = "OLD";
+ NOW = "NOW";
+ ret = "";
+
+ Console.WriteLine("==================================");
+ Console.WriteLine("ref loc: " + STORAGE);
+ Console.WriteLine("Return: " + ret);
+ Console.WriteLine("Comparand:" + NOW);
+ Console.WriteLine("Attempting Exchange in:" + NOW);
+
+ ret = Interlocked.CompareExchange<string>(ref STORAGE,NOW,NOW);
+
+ Console.WriteLine("ref loc: " + STORAGE);
+ Console.WriteLine("Return: " + ret);
+ if(ret != "OLD" || STORAGE != "OLD")
+ retVal = -1;
+
+ Console.WriteLine(100 == retVal ? "Test Passed":"Test Failed");
+ return retVal;
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchanget.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchanget.csproj
new file mode 100644
index 0000000000..c386f1f10e
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchanget.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="CompareExchangeT.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetneg.il b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetneg.il
deleted file mode 100644
index 0acce7968c..0000000000
--- a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetneg.il
+++ /dev/null
@@ -1,95 +0,0 @@
-.assembly extern mscorlib
-{
- .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
- .ver 2:0:0:0
-}
-.assembly CompareExchangeTNeg{}
-
-.class Test
-{
- .method public hidebysig static int32 Main() cil managed
- {
- .entrypoint
- .custom instance void [mscorlib]System.Security.SecuritySafeCriticalAttribute::.ctor() = ( 01 00 00 00 )
- // Code size 101 (0x65)
- .maxstack 3
- .locals init (int32 V_0,
- object V_1,
- object V_2,
- class [mscorlib]System.Exception V_3,
- int32 V_4,
-//Next line was added
- object& V_5)
- IL_0000: ldc.i4.m1
- IL_0001: stloc.0
- IL_0002: ldstr "Start Test"
- IL_0007: call void [mscorlib]System.Console::WriteLine(string)
- IL_000c: nop
- .try
- {
-//Next line was changed to
- IL_000d: ldloc.s 5
-//From
-// IL_000d: ldloc.s 1
- IL_0011: ldstr "hello world"
- IL_0016: ldstr "goodbye world"
- IL_001b: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange<object>(!!0&,
- !!0,
- !!0)
- IL_0020: stloc.2
- IL_0021: nop
- IL_0022: leave.s IL_0045
-
- } // end .try
- catch [mscorlib]System.NullReferenceException
- {
- IL_0024: pop
- IL_0025: ldc.i4.s 100
- IL_0027: stloc.0
- IL_0028: nop
- IL_0029: leave.s IL_0045
-
- } // end handler
- catch [mscorlib]System.Exception
- {
- IL_002b: stloc.3
- IL_002c: ldstr "Wrong exception thrown: "
- IL_0031: ldloc.3
- IL_0032: callvirt instance string [mscorlib]System.Object::ToString()
- IL_0037: call string [mscorlib]System.String::Concat(string,
- string)
- IL_003c: call void [mscorlib]System.Console::WriteLine(string)
- IL_0041: nop
- IL_0042: nop
- IL_0043: leave.s IL_0045
-
- } // end handler
- IL_0045: nop
- IL_0046: ldc.i4.s 100
- IL_0048: ldloc.0
- IL_0049: beq.s IL_0052
-
- IL_004b: ldstr "Test Failed"
- IL_0050: br.s IL_0057
-
- IL_0052: ldstr "Test Passed"
- IL_0057: call void [mscorlib]System.Console::WriteLine(string)
- IL_005c: nop
- IL_005d: ldloc.0
- IL_005e: stloc.s V_4
- IL_0060: br.s IL_0062
-
- IL_0062: ldloc.s V_4
- IL_0064: ret
- } // end of method Test::Main
-
- .method public hidebysig specialname rtspecialname
- instance void .ctor() cil managed
- {
- // Code size 7 (0x7)
- .maxstack 8
- IL_0000: ldarg.0
- IL_0001: call instance void [mscorlib]System.Object::.ctor()
- IL_0006: ret
- } // end of method Test::.ctor
-}
diff --git a/tests/src/baseservices/threading/interlocked/ctorchk/app.config b/tests/src/baseservices/threading/interlocked/ctorchk/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/ctorchk/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/interlocked/ctorchk/ctorchk.cs b/tests/src/baseservices/threading/interlocked/ctorchk/ctorchk.cs
new file mode 100644
index 0000000000..6163bd50fe
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/ctorchk/ctorchk.cs
@@ -0,0 +1,30 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Reflection;
+
+class TestMonitor
+{
+ public static int Main()
+ {
+ // This will look for any private constructor.
+ // There shouldn't be one in Whidbey.
+ ConstructorInfo[] m = typeof(Interlocked).GetConstructors(
+ BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
+ Console.WriteLine(m.Length);
+
+ if(m.Length > 0)
+ {
+ Console.WriteLine("Test FAILED!");
+ return 1;
+ }
+ else
+ {
+ Console.WriteLine("Test PASSED!");
+ return 100;
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/ctorchk/ctorchk.csproj b/tests/src/baseservices/threading/interlocked/ctorchk/ctorchk.csproj
new file mode 100644
index 0000000000..d30c021346
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/ctorchk/ctorchk.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="CtorChk.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/ctorchk/project.json b/tests/src/baseservices/threading/interlocked/ctorchk/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/ctorchk/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/decrement/app.config b/tests/src/baseservices/threading/interlocked/decrement/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/decrement/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/interlocked/decrement/intdec.cs b/tests/src/baseservices/threading/interlocked/decrement/intdec.cs
new file mode 100644
index 0000000000..c3b31073f3
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/decrement/intdec.cs
@@ -0,0 +1,32 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedTest
+{
+ class InterlockTest
+ {
+
+ public static int Main(string[] Args)
+ {
+ int rValue;
+ int loops = 5000;
+ int threads = 50;
+ if (Args.Length == 2)
+ {
+ loops = Int32.Parse(Args[0]);
+ threads = Int32.Parse(Args[1]);
+ }
+ Console.WriteLine("Starting Interlocked test on {0} threads for {1} iterations.",threads,loops);
+
+ IntTest testInt = new IntTest(loops, threads);
+
+ Console.WriteLine("Check Decrement: {0}", rValue = testInt.Dec());
+ Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/decrement/intdec.csproj b/tests/src/baseservices/threading/interlocked/decrement/intdec.csproj
new file mode 100644
index 0000000000..3691c819df
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/decrement/intdec.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="IntDec.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/decrement/longdec.cs b/tests/src/baseservices/threading/interlocked/decrement/longdec.cs
new file mode 100644
index 0000000000..74045ee951
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/decrement/longdec.cs
@@ -0,0 +1,31 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedTest
+{
+ class InterlockTest
+ {
+ public static int Main(string[] Args)
+ {
+ int rValue;
+ int loops = 5000;
+ int threads = 50;
+ if (Args.Length == 2)
+ {
+ loops = Int32.Parse(Args[0]);
+ threads = Int32.Parse(Args[1]);
+ }
+ Console.WriteLine("Starting Interlocked test on {0} threads for {1} iterations.",threads,loops);
+
+ LongTest testLong = new LongTest(loops, threads);
+
+ Console.WriteLine("Check Decrement: {0}", rValue = testLong.Dec());
+ Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/decrement/longdec.csproj b/tests/src/baseservices/threading/interlocked/decrement/longdec.csproj
new file mode 100644
index 0000000000..64a695ff7c
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/decrement/longdec.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="LongDec.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/decrement/project.json b/tests/src/baseservices/threading/interlocked/decrement/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/decrement/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange1_cti.cs b/tests/src/baseservices/threading/interlocked/exchange/exchange1_cti.cs
new file mode 100644
index 0000000000..fb682e093b
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange1_cti.cs
@@ -0,0 +1,165 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections;
+using System.Threading;
+
+/// <summary>
+/// System.Threading.Interlocked.Exchange(System.Double@,System.Double)
+/// </summary>
+
+
+// This test makes sure that Exchange(Double, Double)
+// plays nicely with other threads accessing shared state directly.
+// The test spawns a bunch of threads, then each thread tries to
+// grab the mutex (set location=1), decrement a global resource count,
+// then release the mutex (set location=0). While location=0, the
+// thread will be able to set it to 1 and enter the mutex to consume
+// the resource, but if it is 1, the thread will be denied entry.
+// At the end, the test checks that:
+// the sum of all entries + denials = total potential resources
+// total potential resources = resources unconsumed + entries
+public class InterlockedExchange1
+{
+ private const int c_THREADARRAT_SIZE = 10; // how many threads to spawn
+ private const int c_WAITTHREADSCOMPLETE = 3000; // how long main thread should sleep
+ private static int resource = 10; // resources to be consumed
+ private static double location = 0; // mutex being managed thru Exchange
+ private static int entry = 0; // threads granted entry to the mutex
+ private static int deny = 0; // threads denied entry to the mutex
+
+ public static int Main(string[] args)
+ {
+ InterlockedExchange1 exchange1 = new InterlockedExchange1();
+ TestLibrary.TestFramework.BeginTestCase("Testing System.Threading.Interlocked.Exchange(System.Double@,System.Double)...");
+
+ if (exchange1.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ return retVal;
+ }
+
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Verify multiple threads share the same resource by using Interlocked.Exchange method...");
+
+ try
+ {
+ // create an array of many threads
+ Thread[] threads = new Thread[c_THREADARRAT_SIZE];
+ Random rand = new Random();
+
+ // for each thread
+ for (int i = 0; i < threads.Length; i++)
+ {
+ // each thread uses ConsumeResource
+ threads[i] = new Thread(new ThreadStart(ConsumeResource));
+ // and has a name
+ threads[i].Name = String.Format("Thread{0}",i+1);
+ // put the spawning thread to sleep for a random period of time
+ Thread.Sleep(rand.Next(1,100));
+ // then start the spawned thread working
+ threads[i].Start();
+ }
+
+ // after all threads are spawned, put the spawining thread
+ // to sleep for long enough that the spawned threads have
+ // time to complete
+ Thread.Sleep(c_WAITTHREADSCOMPLETE);
+
+ // entries + denials should equal original value of resource (10)
+ if (entry + deny == 10)
+ {
+ // if any resources remain unconsumed, then those plus number
+ // of successful entries should equal the original value of
+ // resource (10)
+ if (resource > 0 && resource + entry != 10)
+ {
+ TestLibrary.TestFramework.LogError("001","The number of resources consumed is wrong!");
+ retVal = false;
+ }
+ }
+ else
+ {
+ TestLibrary.TestFramework.LogError("002","The total number is wrong!");
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("003","Unexpected exception occurs: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ private static void ConsumeResource()
+ {
+ // This is effectively a hand-coded mutex.
+ // The thread exchanges the value 1 with the value
+ // already at location (initially 0). So first time, it should
+ // set location=1 and return 0. When it gets back the 0, it knows
+ // it holds the mutex. So the thread 'consumes' a
+ // resource and records an 'entry', after which it sets location
+ // back to 0, effectively releasing the mutex.
+ // Any thread hitting the first Exchange while location=1 will
+ // be returned the 1, and thus not enter the mutex - it will
+ // just record a 'denial' and not 'consume' a resource.
+ // After all is said and done, denials+entries should equal total
+ // initial resources.
+
+ // obtain the mutex by putting a 1 there and getting back a 0)
+ if (Interlocked.Exchange(ref location, 1) == 0) // corrected, was !=0
+ {
+ // this thread has the mutex
+ if (resource > 0)
+ {
+ // consume a resource
+ resource--;
+ TestLibrary.TestFramework.LogInformation(String.Format("The resource is reduced, the remainder is {0}",resource));
+ }
+ else
+ {
+ // no more resources to consume - this really should never happen
+ TestLibrary.TestFramework.LogInformation("The resource is empty!");
+ }
+
+ // release the mutex (put a 0 back in location)
+ Interlocked.Exchange(ref location,0);
+ // increment the entry count -
+ Interlocked.Increment(ref entry); // corrected, was entry++;
+ // which is not thread safe;
+ }
+ else
+ {
+ // the thread could not enter the mutex because another
+ // thread has set the location to 1
+ TestLibrary.TestFramework.LogInformation("This is not available!");
+ // increment the denial count, no resource is consumed
+ Interlocked.Increment(ref deny); // corrected, was deny++;
+ // which is not thread safe;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange1_cti.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchange1_cti.csproj
new file mode 100644
index 0000000000..7a65fc77dd
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange1_cti.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="Exchange1_cti.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange2.cs b/tests/src/baseservices/threading/interlocked/exchange/exchange2.cs
new file mode 100644
index 0000000000..a4ba8ff836
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange2.cs
@@ -0,0 +1,150 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// Tests that Exchange(object, object) works on variety
+// of casted types: It just casts a bunch of different types to
+// object, then makes sure Exchange works on those objects.
+public class InterlockedExchange2
+{
+ private const int c_NUM_LOOPS = 100;
+ private const int c_MIN_STRING_LEN = 5;
+ private const int c_MAX_STRING_LEN = 128;
+
+ public static int Main()
+ {
+ InterlockedExchange2 test = new InterlockedExchange2();
+
+ TestLibrary.TestFramework.BeginTestCase("InterlockedExchange2");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ return retVal;
+ }
+
+ public bool PosTest1()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object Interlocked.Exchange(objct&,object)");
+
+ try
+ {
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Byte");
+ retVal = ExchangeObjects(
+ (object)TestLibrary.Generator.GetByte(),
+ (object)TestLibrary.Generator.GetByte()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Byte[]");
+ byte[] bArr1 = new Byte[5 + (TestLibrary.Generator.GetInt32() % 1024)];
+ byte[] bArr2 = new Byte[5 + (TestLibrary.Generator.GetInt32() % 1024)];
+ TestLibrary.Generator.GetBytes(bArr1);
+ TestLibrary.Generator.GetBytes(bArr2);
+ retVal = ExchangeObjects(
+ (object)bArr1,
+ (object)bArr2
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Int16");
+ retVal = ExchangeObjects(
+ (object)TestLibrary.Generator.GetInt16(),
+ (object)TestLibrary.Generator.GetInt16()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Int32");
+ retVal = ExchangeObjects(
+ (object)TestLibrary.Generator.GetInt32(),
+ (object)TestLibrary.Generator.GetInt32()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Int64");
+ retVal = ExchangeObjects(
+ (object)(object)TestLibrary.Generator.GetInt64(),
+ (object)TestLibrary.Generator.GetInt64()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Single");
+ retVal = ExchangeObjects(
+ (object)(object)TestLibrary.Generator.GetSingle(),
+ (object)TestLibrary.Generator.GetSingle()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == Double");
+ retVal = ExchangeObjects(
+ (object)TestLibrary.Generator.GetDouble(),
+ (object)TestLibrary.Generator.GetDouble()
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == string");
+ retVal = ExchangeObjects(
+ TestLibrary.Generator.GetString(false, c_MIN_STRING_LEN, c_MAX_STRING_LEN),
+ (object)TestLibrary.Generator.GetString(false, c_MIN_STRING_LEN, c_MAX_STRING_LEN)
+ ) && retVal;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: object == char");
+ retVal = ExchangeObjects(
+ TestLibrary.Generator.GetChar(),
+ TestLibrary.Generator.GetChar()
+ ) && retVal;
+
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ public bool ExchangeObjects(object location, object value)
+ {
+ bool retVal = true;
+ object oldLocation;
+ object prevLocation;
+
+ prevLocation = location;
+
+ // this is the main change from InterlockedExchange2.cs
+ // here we use the object overload
+ oldLocation = Interlocked.Exchange(ref location, value);
+
+ if (!location.Equals(value))
+ {
+ TestLibrary.TestFramework.LogError("003", "Interlocked.Exchange() did not do the exchange correctly: Expected(" + value + ") Actual(" + location + ")");
+ retVal = false;
+ }
+
+ if (!oldLocation.Equals(prevLocation))
+ {
+ TestLibrary.TestFramework.LogError("004", "Interlocked.Exchange() did not return the expected value: Expected(" + prevLocation + ") Actual(" + oldLocation + ")");
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange2.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchange2.csproj
new file mode 100644
index 0000000000..99ead4425d
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange2.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="Exchange2.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange3.cs b/tests/src/baseservices/threading/interlocked/exchange/exchange3.cs
new file mode 100644
index 0000000000..ed5ea017f3
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange3.cs
@@ -0,0 +1,86 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// Tests that Exchange(Double, Double)
+// actually switches values
+public class InterlockedExchange3
+{
+ private const int c_NUM_LOOPS = 100;
+
+ public static int Main()
+ {
+ InterlockedExchange3 test = new InterlockedExchange3();
+
+ TestLibrary.TestFramework.BeginTestCase("InterlockedExchange3");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ return retVal;
+ }
+
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ Double location;
+ Double value;
+ Double prevLocation;
+ Double oldLocation;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Double Interlocked.Exchange(Double&,Double)");
+
+ try
+ {
+ for (int i=0; i<c_NUM_LOOPS; i++)
+ {
+ value = TestLibrary.Generator.GetDouble();
+ location = TestLibrary.Generator.GetDouble();
+ prevLocation = location;
+
+ oldLocation = Interlocked.Exchange(ref location, value);
+
+ if (!location.Equals(value))
+ {
+ TestLibrary.TestFramework.LogError("001", "Interlocked.Exchange() did not do the exchange correctly: Expected(" + value + ") Actual(" + location + ")");
+ retVal = false;
+ }
+
+ if (!oldLocation.Equals(prevLocation))
+ {
+ TestLibrary.TestFramework.LogError("002", "Interlocked.Exchange() did not return the expected value: Expected(" + prevLocation + ") Actual(" + oldLocation + ")");
+ retVal = false;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange3.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchange3.csproj
new file mode 100644
index 0000000000..7cdc58bee7
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange3.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="Exchange3.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange4.cs b/tests/src/baseservices/threading/interlocked/exchange/exchange4.cs
new file mode 100644
index 0000000000..85cc51dc09
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange4.cs
@@ -0,0 +1,86 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// Tests that Exchange(Single, Single)
+// a.k.a., CompareExchange(float, float)
+// actually switches values
+public class InterlockedExchange4
+{
+ private const int c_NUM_LOOPS = 100;
+
+ public static int Main()
+ {
+ InterlockedExchange4 test = new InterlockedExchange4();
+
+ TestLibrary.TestFramework.BeginTestCase("InterlockedExchange4");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ return retVal;
+ }
+
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ Single location;
+ Single value;
+ Single prevLocation;
+ Single oldLocation;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Single Interlocked.Exchange(Single&,Single)");
+
+ try
+ {
+ for (int i=0; i<c_NUM_LOOPS; i++)
+ {
+ value = TestLibrary.Generator.GetSingle();
+ location = TestLibrary.Generator.GetSingle();
+ prevLocation = location;
+
+ oldLocation = Interlocked.Exchange(ref location, value);
+
+ if (!location.Equals(value))
+ {
+ TestLibrary.TestFramework.LogError("001", "Interlocked.Exchange() did not do the exchange correctly: Expected(" + value + ") Actual(" + location + ")");
+ retVal = false;
+ }
+
+ if (!oldLocation.Equals(prevLocation))
+ {
+ TestLibrary.TestFramework.LogError("002", "Interlocked.Exchange() did not return the expected value: Expected(" + prevLocation + ") Actual(" + oldLocation + ")");
+ retVal = false;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange4.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchange4.csproj
new file mode 100644
index 0000000000..af7203e4e9
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange4.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="Exchange4.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange4_cti.cs b/tests/src/baseservices/threading/interlocked/exchange/exchange4_cti.cs
new file mode 100644
index 0000000000..ba38b07ad2
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange4_cti.cs
@@ -0,0 +1,165 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections;
+using System.Threading;
+
+/// <summary>
+/// System.Threading.Interlocked.Exchange(System.Single@,System.Single)
+/// </summary>
+
+
+// This test makes sure that Exchange(Single, Single)
+// plays nicely with other threads accessing shared state directly.
+// The test spawns a bunch of threads, then each thread tries to
+// grab the mutex (set location=1), decrement a global resource count,
+// then release the mutex (set location=0). While location=0, the
+// thread will be able to set it to 1 and enter the mutex to consume
+// the resource, but if it is 1, the thread will be denied entry.
+// At the end, the test checks that:
+// the sum of all entries + denials = total potential resources
+// total potential resources = resources unconsumed + entries
+public class InterlockedExchange4
+{
+ private const int c_THREADARRAT_SIZE = 10; // how many threads to spawn
+ private const int c_WAITTHREADSCOMPLETE = 2000; // how long main thread should sleep
+ private static int resource = 10; // resources to be consumed
+ private static Int64 location = 0; // mutex being managed thru Exchange
+ private static int entry = 0; // threads granted entry to the mutex
+ private static int deny = 0; // threads denied entry to the mutex
+
+ public static int Main(string[] args)
+ {
+ InterlockedExchange4 exchange4 = new InterlockedExchange4();
+ TestLibrary.TestFramework.BeginTestCase("Testing System.Threading.Interlocked.Exchange(System.Single@,System.Single)...");
+
+ if (exchange4.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ return retVal;
+ }
+
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Verify multiple threads share the same resource by using Interlocked.Exchange method...");
+
+ try
+ {
+ // create an array of many threads
+ Thread[] threads = new Thread[c_THREADARRAT_SIZE];
+ Random rand = new Random();
+
+ // for each thread
+ for (int i = 0; i < threads.Length; i++)
+ {
+ // each thread uses ConsumeResource
+ threads[i] = new Thread(new ThreadStart(ConsumeResource));
+ // and has a name
+ threads[i].Name = String.Format("Thread{0}", i + 1);
+ // put the spawning thread to sleep for a random period of time
+ Thread.Sleep(rand.Next(1, 100));
+ // then start the spawned thread working
+ threads[i].Start();
+ }
+
+ // after all threads are spawned, put the spawining thread
+ // to sleep for long enough that the spawned threads have
+ // time to complete
+ Thread.Sleep(c_WAITTHREADSCOMPLETE);
+
+ // entries + denials should equal original value of resource (10)
+ if (entry + deny == 10)
+ {
+ // if any resources remain unconsumed, then those plus number
+ // of successful entries should equal the original value of
+ // resource (10)
+ if (resource > 0 && resource + entry != 10)
+ {
+ TestLibrary.TestFramework.LogError("001", "The number of resource is consumed is wrong!");
+ retVal = false;
+ }
+ }
+ else
+ {
+ TestLibrary.TestFramework.LogError("002", "The total number is wrong!");
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("003", "Unexpected exception occurs: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ private static void ConsumeResource()
+ {
+ // This is effectively a hand-coded mutex.
+ // The thread exchanges the value 1 with the value
+ // already at location (initially 0). So first time, it should
+ // set location=1 and return 0. When it gets back the 0, it knows
+ // it holds the mutex. So the thread 'consumes' a
+ // resource and records an 'entry', after which it sets location
+ // back to 0, effectively releasing the mutex.
+ // Any thread hitting the first Exchange while location=1 will
+ // be returned the 1, and thus not enter the mutex - it will
+ // just record a 'denial' and not 'consume' a resource.
+ // After all is said and done, denials+entries should equal total
+ // original resources.
+
+ // obtain the mutex by putting a 1 there and getting back a 0)
+ if (Interlocked.Exchange(ref location, 1) == 0) // corrected, was !=0
+ {
+ // this thread has the mutex
+ if (resource > 0)
+ {
+ // consume a resource
+ resource--;
+ TestLibrary.TestFramework.LogInformation(String.Format("The resource is reduced,the rest number is {0}", resource));
+ }
+ else
+ {
+ // no more resources to consume - this really should never happen
+ TestLibrary.TestFramework.LogInformation("The resource is empty!");
+ }
+
+ // release the mutex (put a 0 back in location)
+ Interlocked.Exchange(ref location, 0);
+ // increment the entry count -
+ Interlocked.Increment(ref entry); // corrected, was entry++;
+ // which is not thread safe;
+ }
+ else
+ {
+ // the thread could not enter the mutex because another
+ // thread has set the location to 1
+ TestLibrary.TestFramework.LogInformation("This is not available!");
+ // increment the denial count, no resource is consumed
+ Interlocked.Increment(ref deny); // corrected, was deny++;
+ // which is not thread safe;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange4_cti.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchange4_cti.csproj
new file mode 100644
index 0000000000..00691e700c
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange4_cti.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="Exchange4_cti.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange5_cti.cs b/tests/src/baseservices/threading/interlocked/exchange/exchange5_cti.cs
new file mode 100644
index 0000000000..af0da2a532
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange5_cti.cs
@@ -0,0 +1,165 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections;
+using System.Threading;
+
+/// <summary>
+/// System.Threading.Interlocked.Exchange(System.Object@,System.Object)
+/// </summary>
+
+
+// This test makes sure that Exchange(object, object)
+// plays nicely with other threads accessing shared state directly.
+// The test spawns a bunch of threads, then each thread tries to
+// grab the mutex (set location=1), decrement a global resource count,
+// then release the mutex (set location=0). While location=0, the
+// thread will be able to set it to 1 and enter the mutex to consume
+// the resource, but if it is 1, the thread will be denied entry.
+// At the end, the test checks that:
+// the sum of all entries + denials = total potential resources
+// total potential resources = resources unconsumed + entries
+public class InterlockedExchange5
+{
+ private const int c_THREADARRAT_SIZE = 10; // how many threads to spawn
+ private const int c_WAITTHREADSCOMPLETE = 2000; // how long main thread should sleep
+ private static int resource = 10; // resources to be consumed
+ private static Object location = 0; // mutex being managed thru Exchange
+ private static int entry = 0; // threads granted entry to the mutex
+ private static int deny = 0; // threads denied entry to the mutex
+
+ public static int Main(string[] args)
+ {
+ InterlockedExchange5 exchange5 = new InterlockedExchange5();
+ TestLibrary.TestFramework.BeginTestCase("Testing System.Threading.Interlocked.Exchange(System.Object@,System.Object)...");
+
+ if (exchange5.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ return retVal;
+ }
+
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Verify multiple threads share the same resource by using Interlocked.Exchange method...");
+
+ try
+ {
+ // create an array of many threads
+ Thread[] threads = new Thread[c_THREADARRAT_SIZE];
+ Random rand = new Random();
+
+ // for each thread
+ for (int i = 0; i < threads.Length; i++)
+ {
+ // each thread uses ConsumeResource
+ threads[i] = new Thread(new ThreadStart(ConsumeResource));
+ // and has a name
+ threads[i].Name = String.Format("Thread{0}", i + 1);
+ // put this (the spawning) thread to sleep for a random period of time
+ Thread.Sleep(rand.Next(1, 100));
+ // then start the spawned thread working
+ threads[i].Start();
+ }
+
+ // after all threads are spawned, put the spawining thread
+ // to sleep for long enough that the spawned threads have
+ // time to complete
+ Thread.Sleep(c_WAITTHREADSCOMPLETE);
+
+ // entries + denials should equal original value of resource (10)
+ if (entry + deny == 10)
+ {
+ // if any resources remain unconsumed, then those plus number
+ // of successful entries should equal the original value of
+ // resource (10)
+ if (resource > 0 && resource + entry != 10)
+ {
+ TestLibrary.TestFramework.LogError("001", "The number of resource is consumed is wrong!");
+ retVal = false;
+ }
+ }
+ else
+ {
+ TestLibrary.TestFramework.LogError("002", "The total number is wrong!");
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("003", "Unexpected exception occurs: " + e);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ private static void ConsumeResource()
+ {
+ // This is effectively a hand-coded mutex.
+ // The thread exchanges the value 1 with the value
+ // already at location (initially 0). So first time, it should
+ // set location=1 and return 0. Then the thread 'consumes' a
+ // resource and records an 'entry', after which it sets location
+ // back to 0. Any thread hitting the Exchange while loc=1 will see
+ // this and not enter the mutex - it will just record a 'denial'.
+ // After all is said and done, denials+entries should equal total
+ // resources consumed.
+ // note that since location is actually an object, Exchange is going
+ // to return an object which must be converted to Int32
+ // note that here we use the object overload of Interlocked.Exchange
+ if (Convert.ToInt32(Interlocked.Exchange(ref location, 1)) == 0) // corrected, was !=0
+ {
+ // this thread has the mutex
+ if (resource > 0)
+ {
+ // consume a resource
+ resource--;
+ TestLibrary.TestFramework.LogInformation(String.Format("The resource is reduced, the remainder is {0}", resource));
+ }
+ else
+ {
+ // no more resources to consume - this really should never happen
+ TestLibrary.TestFramework.LogInformation("The resource is empty!");
+ }
+
+ // release the mutex
+ // note that here we use the object overload
+ // of Exchange
+ Interlocked.Exchange(ref location, 0);
+ // increment the entry count -
+ Interlocked.Increment(ref entry); // corrected, was entry++;
+ // which is not thread safe
+ }
+ else
+ {
+ // the thread could not enter the mutex because another
+ // thread has set the location to 1
+ TestLibrary.TestFramework.LogInformation("This is not available!");
+ // increment the denial count, no resource is consumed
+ Interlocked.Increment(ref deny); // corrected, was deny++;
+ // which is not thread safe
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchange5_cti.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchange5_cti.csproj
new file mode 100644
index 0000000000..6d05ac51db
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchange5_cti.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="Exchange5_cti.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchangedouble.cs b/tests/src/baseservices/threading/interlocked/exchange/exchangedouble.cs
new file mode 100644
index 0000000000..385f549eb3
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchangedouble.cs
@@ -0,0 +1,99 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace Exchange
+{
+ class ExchangeDouble
+ {
+ static int Main(string[] args)
+ {
+ int rValue = 0;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe();
+ for (int i = 0; i < threads.Length - 1; i++)
+ {
+ if (i % 2 == 0)
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerA));
+ else
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerB));
+ threads[i].Start();
+ }
+ threads[threads.Length - 1] = new Thread(new ThreadStart(tsi.ThreadChecker));
+ threads[threads.Length - 1].Start();
+ tsi.Signal();
+
+ for (int i = 0; i < threads.Length; i++)
+ threads[i].Join();
+
+ if (tsi.Pass)
+ rValue = 100;
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ ManualResetEvent signal;
+ private double totalValue = Double.MinValue;
+ private int numberOfIterations;
+ private double newValueA = 0.0D;
+ private double newValueB = Double.MinValue;
+ private bool success;
+ public ThreadSafe(): this(10000) { }
+ public ThreadSafe(int loops)
+ {
+ success = true;
+ signal = new ManualResetEvent(false);
+ numberOfIterations = loops;
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+
+ public void ThreadWorkerA()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < numberOfIterations; i++)
+ Interlocked.Exchange(ref totalValue, newValueA);
+ }
+
+ public void ThreadWorkerB()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < numberOfIterations; i++)
+ Interlocked.Exchange(ref totalValue, newValueB);
+ }
+
+ public void ThreadChecker()
+ {
+ double tmpVal;
+ signal.WaitOne();
+ for (int i = 0; i < numberOfIterations; i++)
+ {
+ tmpVal = totalValue;
+ if (tmpVal != newValueB && tmpVal != newValueA)
+ {
+ Console.WriteLine(tmpVal + "," +
+ newValueB + "," + newValueA);
+ success = false;
+ }
+ Thread.Sleep(0);
+ }
+ }
+
+ public bool Pass
+ {
+ get
+ {
+ return (success);
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchangedouble.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchangedouble.csproj
new file mode 100644
index 0000000000..48f49f27e1
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchangedouble.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ExchangeDouble.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.cs b/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.cs
new file mode 100644
index 0000000000..0811db9469
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.cs
@@ -0,0 +1,107 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace Exchange
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ class Class1
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static int Main(string[] args)
+ {
+ int rValue = 0;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe();
+ for (int i = 0; i < threads.Length - 1; i++)
+ {
+ if (i % 2 == 0)
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerA));
+ else
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerB));
+ threads[i].Start();
+ }
+ threads[threads.Length - 1] = new Thread(new ThreadStart(tsi.ThreadChecker));
+ threads[threads.Length - 1].Start();
+ tsi.Signal();
+
+ for (int i = 0; i < threads.Length; i++)
+ threads[i].Join();
+
+ if (tsi.Pass)
+ rValue = 100;
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ ManualResetEvent signal;
+ private float totalValue = Single.MinValue;
+ private int numberOfIterations;
+ private float newValueA = 0.0F;
+ private float newValueB = Single.MinValue;
+ private bool success;
+ public ThreadSafe(): this(10000) { }
+ public ThreadSafe(int loops)
+ {
+ success = true;
+ signal = new ManualResetEvent(false);
+ numberOfIterations = loops;
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+
+ public void ThreadWorkerA()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < numberOfIterations; i++)
+ Interlocked.Exchange(ref totalValue, newValueA);
+
+ }
+ public void ThreadWorkerB()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < numberOfIterations; i++)
+ Interlocked.Exchange(ref totalValue, newValueB);
+
+ }
+ public void ThreadChecker()
+ {
+ float tmpVal;
+ signal.WaitOne();
+ for (int i = 0; i < numberOfIterations; i++)
+ {
+ tmpVal = totalValue;
+ if (tmpVal != newValueB && tmpVal != newValueA)
+ {
+
+ Console.WriteLine(tmpVal + "," + newValueB + "," + newValueA);
+ success = false;
+ }
+ Thread.Sleep(0);
+ }
+
+ }
+
+ public bool Pass
+ {
+ get
+ {
+ return (success);
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.csproj
new file mode 100644
index 0000000000..6628d34996
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ExchangeFloat.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.cs b/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.cs
new file mode 100644
index 0000000000..09fa32a46f
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.cs
@@ -0,0 +1,107 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InteropTests
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ class ExchangeObject
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static int Main(string[] args)
+ {
+ int rValue = 0;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe();
+ for (int i = 0; i < threads.Length - 1; i++)
+ {
+ if (i % 2 == 0)
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerA));
+ else
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerB));
+ threads[i].Start();
+ }
+ threads[threads.Length - 1] = new Thread(new ThreadStart(tsi.ThreadChecker));
+ threads[threads.Length - 1].Start();
+ tsi.Signal();
+
+ for (int i = 0; i < threads.Length; i++)
+ threads[i].Join();
+
+ if (tsi.Pass)
+ rValue = 100;
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ ManualResetEvent signal;
+ private Object totalValue = null;
+ private int numberOfIterations;
+ private Object newValueA = new Object();
+ private Object newValueB = new Object();
+ private bool success;
+ public ThreadSafe(): this(10000) { }
+ public ThreadSafe(int loops)
+ {
+ totalValue = newValueA;
+ success = true;
+ signal = new ManualResetEvent(false);
+ numberOfIterations = loops;
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+
+ public void ThreadWorkerA()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < numberOfIterations; i++)
+ Interlocked.Exchange(ref totalValue, newValueB);
+
+ }
+ public void ThreadWorkerB()
+ {
+ signal.WaitOne();
+ for (int i = 0; i < numberOfIterations; i++)
+ Interlocked.Exchange(ref totalValue, newValueB);
+
+ }
+ public void ThreadChecker()
+ {
+ signal.WaitOne();
+ Object tmpVal;
+ for (int i = 0; i < numberOfIterations; i++)
+ {
+ tmpVal = totalValue;
+ if (tmpVal != newValueB && tmpVal != newValueA)
+ {
+ Console.WriteLine(tmpVal + "," + newValueB + "," + newValueA);
+ success = false;
+ }
+ Thread.Sleep(0);
+ }
+
+ }
+
+ public bool Pass
+ {
+ get
+ {
+ return (success);
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.csproj
new file mode 100644
index 0000000000..9032d1baca
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ExchangeObject.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchanget.cs b/tests/src/baseservices/threading/interlocked/exchange/exchanget.cs
new file mode 100644
index 0000000000..6e54966049
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchanget.cs
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class Test
+{
+
+ public static int Main()
+ {
+ Console.WriteLine("Start");
+ int retVal = 100;
+ string STORAGE = "OLD";
+ string NOW = "NOW";
+ string ret = "";
+
+ Console.WriteLine("ref loc: " + STORAGE);
+ Console.WriteLine("Return: " + ret);
+
+ Console.WriteLine("Echanging in:" + NOW);
+
+ string OLDSTORAGE = STORAGE;
+ ret = Interlocked.Exchange<string>(ref STORAGE,NOW);
+
+ Console.WriteLine("ref loc: " + STORAGE);
+ Console.WriteLine("Return: " + ret);
+
+ //if(ret == "" || STORAGE != NOW)
+ if(ret != OLDSTORAGE || STORAGE != NOW)
+ retVal = -1;
+
+ if (retVal == 100)
+ Console.WriteLine("Test passed");
+ else
+ Console.WriteLine("Test failed");
+
+ return retVal;
+
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchanget.csproj b/tests/src/baseservices/threading/interlocked/exchange/exchanget.csproj
new file mode 100644
index 0000000000..7f43d19ef8
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchanget.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ExchangeT.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/increment/app.config b/tests/src/baseservices/threading/interlocked/increment/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/increment/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/interlocked/increment/intinc.cs b/tests/src/baseservices/threading/interlocked/increment/intinc.cs
new file mode 100644
index 0000000000..0d484bd32e
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/increment/intinc.cs
@@ -0,0 +1,31 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedTest
+{
+ class InterlockTest
+ {
+ public static int Main(string[] Args)
+ {
+ int rValue;
+ int loops = 5000;
+ int threads = 50;
+ if (Args.Length == 2)
+ {
+ loops = Int32.Parse(Args[0]);
+ threads = Int32.Parse(Args[1]);
+ }
+ Console.WriteLine("Starting Interlocked test on {0} threads for {1} iterations.",threads,loops);
+
+ IntTest testInt = new IntTest(loops, threads);
+
+ Console.WriteLine("Check Increment: {0}", rValue = testInt.Inc());
+ Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/increment/intinc.csproj b/tests/src/baseservices/threading/interlocked/increment/intinc.csproj
new file mode 100644
index 0000000000..59cd221ede
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/increment/intinc.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="IntInc.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/increment/longinc.cs b/tests/src/baseservices/threading/interlocked/increment/longinc.cs
new file mode 100644
index 0000000000..74045ee951
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/increment/longinc.cs
@@ -0,0 +1,31 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedTest
+{
+ class InterlockTest
+ {
+ public static int Main(string[] Args)
+ {
+ int rValue;
+ int loops = 5000;
+ int threads = 50;
+ if (Args.Length == 2)
+ {
+ loops = Int32.Parse(Args[0]);
+ threads = Int32.Parse(Args[1]);
+ }
+ Console.WriteLine("Starting Interlocked test on {0} threads for {1} iterations.",threads,loops);
+
+ LongTest testLong = new LongTest(loops, threads);
+
+ Console.WriteLine("Check Decrement: {0}", rValue = testLong.Dec());
+ Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/increment/longinc.csproj b/tests/src/baseservices/threading/interlocked/increment/longinc.csproj
new file mode 100644
index 0000000000..feafc55819
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/increment/longinc.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
+ <Compile Include="LongInc.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/increment/project.json b/tests/src/baseservices/threading/interlocked/increment/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/increment/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/read/app.config b/tests/src/baseservices/threading/interlocked/read/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/read/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/interlocked/read/interlockedread.cs b/tests/src/baseservices/threading/interlocked/read/interlockedread.cs
new file mode 100644
index 0000000000..547a4b77af
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/read/interlockedread.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class InterlockedRead
+{
+ ManualResetEvent mre;
+ long lCurr;
+ static int success;
+ const int expected = 5;
+
+ public InterlockedRead()
+ {
+ mre = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ InterlockedRead ir = new InterlockedRead();
+ ir.TestOne(Int64.MaxValue);
+ ir.TestOne(Int64.MinValue);
+ ir.TestOne(0);
+ ir.TestOne(Int32.MaxValue);
+ ir.TestOne(Int32.MinValue);
+ Console.WriteLine(success == expected ? "Test Passed" : "Test Failed");
+ return (success == expected) ? 100 : -1;
+ }
+
+ public void TestOne(long iValue)
+ {
+ bool bRet = true;
+ lCurr = iValue;
+ if(iValue != Interlocked.Read(ref lCurr))
+ bRet = false;
+ if(bRet)
+ success++;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/read/interlockedread.csproj b/tests/src/baseservices/threading/interlocked/read/interlockedread.csproj
new file mode 100644
index 0000000000..b624791b77
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/read/interlockedread.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="InterlockedRead.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/read/project.json b/tests/src/baseservices/threading/interlocked/read/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/read/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/read/readthreads.cs b/tests/src/baseservices/threading/interlocked/read/readthreads.cs
new file mode 100644
index 0000000000..ad839dbc20
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/read/readthreads.cs
@@ -0,0 +1,97 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+namespace InterlockedRead
+{
+ class Read
+ {
+ static int Main(string[] args)
+ {
+ int rValue = 0;
+ Thread[] threads = new Thread[100];
+ ThreadSafe tsi = new ThreadSafe();
+ for (int i = 0; i < threads.Length-1; i++)
+ {
+ if(i%2==0)
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerA));
+ else
+ threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerB));
+ threads[i].Start();
+ }
+ threads[threads.Length-1] = new Thread(new ThreadStart(tsi.ThreadChecker));
+ threads[threads.Length-1].Start();
+ tsi.Signal();
+
+ for(int i=0;i<threads.Length;i++)
+ threads[i].Join();
+
+ if(tsi.Pass)
+ rValue = 100;
+ Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
+ return rValue;
+ }
+ }
+
+ public class ThreadSafe
+ {
+ ManualResetEvent signal;
+ private long totalValue = Int64.MinValue;
+ private int numberOfIterations;
+ private long newValueA = 0;
+ private long newValueB = Int64.MinValue;
+ private bool success;
+ public ThreadSafe(): this(10000) { }
+ public ThreadSafe(int loops)
+ {
+ success = true;
+ signal = new ManualResetEvent(false);
+ numberOfIterations = loops;
+ }
+
+ public void Signal()
+ {
+ signal.Set();
+ }
+
+ public void ThreadWorkerA()
+ {
+ signal.WaitOne();
+ for(int i=0;i<numberOfIterations;i++)
+ Interlocked.Exchange(ref totalValue, newValueA);
+
+ }
+ public void ThreadWorkerB()
+ {
+ signal.WaitOne();
+ for(int i=0;i<numberOfIterations;i++)
+ Interlocked.Exchange(ref totalValue, newValueB);
+ }
+
+ public void ThreadChecker()
+ {
+ signal.WaitOne();
+ for(int i=0;i<numberOfIterations;i++)
+ {
+ long l = Interlocked.Read(ref totalValue);
+ if(l != newValueB && l != newValueA)
+ {
+ Console.WriteLine(l + "," +
+ newValueB + "," + newValueA);
+ success = false;
+ }
+ }
+ }
+
+ public bool Pass
+ {
+ get
+ {
+ return (success);
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/interlocked/read/readthreads.csproj b/tests/src/baseservices/threading/interlocked/read/readthreads.csproj
new file mode 100644
index 0000000000..2a903402cf
--- /dev/null
+++ b/tests/src/baseservices/threading/interlocked/read/readthreads.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ReadThreads.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/ctorchk/app.config b/tests/src/baseservices/threading/monitor/ctorchk/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/ctorchk/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/monitor/ctorchk/ctorchk.cs b/tests/src/baseservices/threading/monitor/ctorchk/ctorchk.cs
new file mode 100644
index 0000000000..f6e9674ff9
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/ctorchk/ctorchk.cs
@@ -0,0 +1,30 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Reflection;
+
+class TestMonitor
+{
+ public static int Main()
+ {
+ // This will look for any private constructor.
+ // There shouldn't be one in Whidbey.
+ ConstructorInfo[] m = typeof(Monitor).GetConstructors(
+ BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
+ Console.WriteLine(m.Length);
+
+ if(m.Length > 0)
+ {
+ Console.WriteLine("Test FAILED!");
+ return 1;
+ }
+ else
+ {
+ Console.WriteLine("Test PASSED!");
+ return 100;
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/ctorchk/ctorchk.csproj b/tests/src/baseservices/threading/monitor/ctorchk/ctorchk.csproj
new file mode 100644
index 0000000000..d30c021346
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/ctorchk/ctorchk.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="CtorChk.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/ctorchk/project.json b/tests/src/baseservices/threading/monitor/ctorchk/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/ctorchk/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/enter/monitorenter.cs b/tests/src/baseservices/threading/monitor/enter/monitorenter.cs
new file mode 100644
index 0000000000..0a9fc4ab4c
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/enter/monitorenter.cs
@@ -0,0 +1,501 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Collections.Generic;
+
+// disable warnings about various Monitor members being obsolete
+#pragma warning disable 0618
+
+class MonEnterTests
+{
+ int m_failed;
+
+ /// <summary>
+ /// Not really negative tests, but testing expected failure modes
+ /// </summary>
+ void NegTests()
+ {
+ Console.WriteLine("null object tests");
+ ExpectException<ArgumentNullException>(delegate { Monitor.Enter(null); });
+ ExpectException<ArgumentNullException>(delegate { Monitor.TryEnter(null); });
+ bool tookLock = false;
+ ExpectException<ArgumentNullException>(delegate { Monitor.Enter(null, ref tookLock); });
+ Assert(!tookLock);
+ tookLock = false;
+ ExpectException<ArgumentNullException>(delegate { Monitor.TryEnter(null, 0, ref tookLock); });
+ Assert(!tookLock);
+ tookLock = false;
+ ExpectException<ArgumentNullException>(delegate { Monitor.TryEnter(null, TimeSpan.Zero, ref tookLock); });
+ Assert(!tookLock);
+ ExpectException<ArgumentNullException>(delegate { Monitor.TryEnter(null, 0); });
+ ExpectException<ArgumentNullException>(delegate { Monitor.TryEnter(null, TimeSpan.Zero); });
+
+ Console.WriteLine("tookLock == true tests");
+ object obj = new object();
+ tookLock = true;
+ ExpectException<ArgumentException>(delegate { Monitor.Enter(obj, ref tookLock); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+ tookLock = true;
+ ExpectException<ArgumentException>(delegate { Monitor.TryEnter(obj, ref tookLock); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+ tookLock = true;
+ ExpectException<ArgumentException>(delegate { Monitor.TryEnter(obj, 0, ref tookLock); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+ tookLock = true;
+ ExpectException<ArgumentException>(delegate { Monitor.TryEnter(obj, TimeSpan.Zero, ref tookLock); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+
+ Console.WriteLine("timeout < -1");
+ tookLock = false;
+ ExpectException<ArgumentOutOfRangeException>(delegate { Monitor.TryEnter(obj, -2, ref tookLock); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, tookLock);
+ tookLock = false;
+ ExpectException<ArgumentOutOfRangeException>(delegate { Monitor.TryEnter(obj, TimeSpan.FromMilliseconds(-2), ref tookLock); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, tookLock);
+ ExpectException<ArgumentOutOfRangeException>(delegate { tookLock = Monitor.TryEnter(obj, -2); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, tookLock);
+ ExpectException<ArgumentOutOfRangeException>(delegate { tookLock = Monitor.TryEnter(obj, TimeSpan.FromMilliseconds(-2)); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, tookLock);
+
+ Console.WriteLine("timeout > int.Max");
+ tookLock = false;
+ ExpectException<ArgumentOutOfRangeException>(delegate { Monitor.TryEnter(obj, TimeSpan.FromMilliseconds((double)int.MaxValue + 1), ref tookLock); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, tookLock);
+ ExpectException<ArgumentOutOfRangeException>(delegate { tookLock = Monitor.TryEnter(obj, TimeSpan.FromMilliseconds((double)int.MaxValue + 1)); });
+ AssertTookLockAndRelease(LockIsHeld.No, obj, tookLock);
+ }
+
+
+ AutoResetEvent contentionStartEvent = new AutoResetEvent(false);
+ volatile bool contentionStarted;
+ volatile bool inContention;
+ AutoResetEvent contentionDoneEvent = new AutoResetEvent(false);
+
+ // for some reason I had to add these to get this to build in the test environment
+ delegate void Action();
+ delegate void Action<T>(T arg);
+ delegate void Action<T1,T2>(T1 arg1, T2 arg2);
+
+ /// <summary>
+ /// Runs a lock acquisition scenario (passed in via <paramref name="run"/>) with contention
+ /// on the lock.
+ /// </summary>
+ /// <param name="obj">The object to lock</param>
+ /// <param name="spins">How many times to spin while holding the lock</param>
+ /// <param name="run">A lock acquisition scenario to perform under contention (will be passed
+ /// <paramref name="obj"/> as the object to be locked)</param>
+ void RunWithContention(object obj, int spins, Action<object> run)
+ {
+ ThreadPool.QueueUserWorkItem(delegate
+ {
+ contentionStartEvent.WaitOne();
+ Monitor.Enter(obj);
+ inContention = true;
+ contentionStarted = true;
+ Thread.Sleep(0); // yield
+ inContention = false;
+ Monitor.Exit(obj);
+ contentionDoneEvent.Set();
+ });
+ contentionStarted = false;
+ inContention = false;
+ Thread.Sleep(1);
+ contentionStartEvent.Set();
+ int waitCount = 0;
+ while (!contentionStarted)
+ {
+ waitCount++;
+ if (waitCount > 30000)
+ {
+ //Thread.Yield is internal in CoreClr, so change it to Thread.Sleep(0)
+ // Thread.Yield();
+ Thread.Sleep(0);
+ waitCount = 0;
+ }
+ }
+ run(obj);
+ contentionDoneEvent.WaitOne();
+ }
+
+ /// <summary>
+ /// Runs all tests under varying levels of contention
+ /// </summary>
+ void ContentionVariants()
+ {
+ Console.WriteLine("--- no contention ---");
+ SyncBlkVariants(LockIsHeld.No, delegate(object o, Action<object> ac) { ac(o); });
+
+ Console.WriteLine("--- a little contention ---");
+ SyncBlkVariants(LockIsHeld.Maybe, delegate(object o, Action<object> ac) { RunWithContention(o, 10000, ac); });
+
+ Console.WriteLine("--- lots of contention ---");
+ SyncBlkVariants(LockIsHeld.Maybe, delegate(object o, Action<object> ac) { RunWithContention(o, 1000000, ac); });
+ }
+
+ /// <summary>
+ /// Runs all tests under each SyncBlk variation
+ /// </summary>
+ /// <param name="lockIsHeld">Whether to expect that the lock is being held (experiencing
+ /// contention) while each lock attempt is performed</param>
+ /// <param name="scenario">A lock contention scenario to run under each SyncBlk scenario. Is
+ /// passed an object that may or may not have a SyncBlk, and a lock acquisition scenario to run
+ /// under that level of contention</param>
+ void SyncBlkVariants(LockIsHeld lockIsHeld, Action<object, Action<object>> scenario)
+ {
+ Console.WriteLine("Positive tests, no SyncBlk");
+ MethodVariants(lockIsHeld, delegate(Action<object> innerScenario)
+ {
+ object obj = new object();
+ scenario(obj, delegate(object o) { innerScenario(o); });
+ });
+
+ Console.WriteLine("Positive tests, with HashCode");
+ MethodVariants(lockIsHeld, delegate(Action<object> innerScenario)
+ {
+ object obj = new object();
+ obj.GetHashCode();
+ scenario(obj, delegate(object o) { innerScenario(o); });
+ });
+
+ Console.WriteLine("Positive tests, with SyncBlk");
+ MethodVariants(lockIsHeld, delegate(Action<object> innerScenario)
+ {
+ object obj = new object();
+ obj.GetHashCode();
+ Monitor.Enter(obj);
+ Monitor.Exit(obj);
+ scenario(obj, delegate(object o) { innerScenario(o); });
+ });
+ }
+
+ enum LockIsHeld { Yes, No, Maybe }
+
+ LockIsHeld Reverse(LockIsHeld lockIsHeld)
+ {
+ switch (lockIsHeld)
+ {
+ case LockIsHeld.Yes:
+ return LockIsHeld.No;
+ case LockIsHeld.No:
+ return LockIsHeld.Yes;
+ default:
+ return lockIsHeld;
+ }
+ }
+
+ /// <summary>
+ /// Runs all lock acquisition scenarios inside of an outer contention/SyncBlk scenario
+ /// </summary>
+ /// <param name="lockIsHeld">whether to expect the lock to be held when we try to acquire it</param>
+ /// <param name="scenario">The contention/SyncBlk scenario to run each acquisition scenario inside of.</param>
+ void MethodVariants(LockIsHeld lockIsHeld, Action<Action<object>> scenario)
+ {
+ bool tookLock;
+
+ scenario(delegate(object obj)
+ {
+ Monitor.Enter(obj);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = false;
+ Monitor.Enter(obj, ref tookLock);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = Monitor.TryEnter(obj);
+ AssertTookLockAndRelease(Reverse(lockIsHeld), obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = Monitor.TryEnter(obj, 0);
+ AssertTookLockAndRelease(Reverse(lockIsHeld), obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ DateTime start = DateTime.Now;
+ tookLock = Monitor.TryEnter(obj, 10000);
+ double elapsed = (DateTime.Now - start).TotalSeconds;
+ AssertTookLockAndRelease(elapsed < 5.0 ? LockIsHeld.Yes : LockIsHeld.Maybe, obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = Monitor.TryEnter(obj, Timeout.Infinite);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = Monitor.TryEnter(obj, TimeSpan.FromMilliseconds(0));
+ AssertTookLockAndRelease(Reverse(lockIsHeld), obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = Monitor.TryEnter(obj, TimeSpan.FromMilliseconds(10000));
+ AssertTookLockAndRelease(LockIsHeld.Maybe, obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = Monitor.TryEnter(obj, TimeSpan.FromMilliseconds(Timeout.Infinite));
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = false;
+ Monitor.TryEnter(obj, ref tookLock);
+ AssertTookLockAndRelease(Reverse(lockIsHeld), obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = false;
+ Monitor.TryEnter(obj, 0, ref tookLock);
+ AssertTookLockAndRelease(Reverse(lockIsHeld), obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = false;
+ Monitor.TryEnter(obj, 10000, ref tookLock);
+ AssertTookLockAndRelease(LockIsHeld.Maybe, obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = false;
+ Monitor.TryEnter(obj, Timeout.Infinite, ref tookLock);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = false;
+ Monitor.TryEnter(obj, TimeSpan.FromMilliseconds(0), ref tookLock);
+ AssertTookLockAndRelease(Reverse(lockIsHeld), obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = false;
+ Monitor.TryEnter(obj, TimeSpan.FromMilliseconds(10000), ref tookLock);
+ AssertTookLockAndRelease(LockIsHeld.Maybe, obj, tookLock);
+ });
+
+ scenario(delegate(object obj)
+ {
+ tookLock = false;
+ Monitor.TryEnter(obj, TimeSpan.FromMilliseconds(Timeout.Infinite), ref tookLock);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, tookLock);
+ });
+
+ if (lockIsHeld == LockIsHeld.No)
+ {
+ scenario(delegate(object obj)
+ {
+ Monitor.Enter(obj);
+ Monitor.Enter(obj);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+ });
+
+ scenario(delegate(object obj)
+ {
+ Monitor.Enter(obj);
+ tookLock = false;
+ Monitor.Enter(obj, ref tookLock);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, tookLock);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+ });
+
+ scenario(delegate(object obj)
+ {
+ Monitor.Enter(obj);
+ tookLock = false;
+ Monitor.TryEnter(obj, ref tookLock);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, tookLock);
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+ });
+
+ scenario(delegate(object obj)
+ {
+ Monitor.Enter(obj);
+ for (int i = 0; i < 70; i++)
+ {
+ Monitor.Enter(obj);
+ }
+ for (int i = 0; i < 70; i++)
+ {
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ }
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+ });
+
+ scenario(delegate(object obj)
+ {
+ Monitor.Enter(obj);
+ for (int i = 0; i < 70; i++)
+ {
+ tookLock = false;
+ Monitor.Enter(obj, ref tookLock);
+ Assert(tookLock);
+ }
+ for (int i = 0; i < 70; i++)
+ {
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ }
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+ });
+
+ scenario(delegate(object obj)
+ {
+ Monitor.Enter(obj);
+ for (int i = 0; i < 70; i++)
+ {
+ tookLock = false;
+ Monitor.TryEnter(obj, ref tookLock);
+ Assert(tookLock);
+ }
+ for (int i = 0; i < 70; i++)
+ {
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ }
+ AssertTookLockAndRelease(LockIsHeld.Yes, obj, true);
+ AssertTookLockAndRelease(LockIsHeld.No, obj, false);
+ });
+ }
+ }
+
+ void AssertTookLockAndRelease(LockIsHeld expected, object obj, bool tookLock)
+ {
+ Assert((expected == LockIsHeld.Yes && tookLock) ||
+ (expected == LockIsHeld.No && !tookLock) ||
+ expected == LockIsHeld.Maybe);
+
+ if (tookLock) Assert(!inContention);
+
+ bool exitFailed = false;
+ try
+ {
+ Monitor.Exit(obj);
+ }
+ catch (SynchronizationLockException)
+ {
+ exitFailed = true;
+ }
+
+ Assert(tookLock == !exitFailed);
+ }
+
+ void ExpectException<T>(Action action) where T : Exception
+ {
+ try
+ {
+ action();
+ }
+ catch (Exception e)
+ {
+ if (!(e is T))
+ {
+ FailNoStack("Unexpected exception:\n{0}", e.ToString());
+ }
+ return;
+ }
+ Fail("Expected {0}, but got no exception!", typeof(T).Name);
+ }
+
+ void Assert(bool condition, string message)
+ {
+ if (!condition)
+ Fail(message);
+ }
+
+ void Assert(bool condition)
+ {
+ Assert(condition, "Assertion failed");
+ }
+
+ void Fail(string message, bool printStack)
+ {
+ m_failed++;
+ Console.WriteLine(message);
+ }
+
+ void Fail(string format, params object[] args)
+ {
+ Fail(string.Format(format, args), true);
+ }
+
+ void Fail(string format)
+ {
+ Fail(format, true);
+ }
+
+ void FailNoStack(string format, params object[] args)
+ {
+ Fail(string.Format(format, args), false);
+ }
+
+
+ void ThreadIdPosTests()
+ {
+ Console.WriteLine("*** High thread ID tests ***");
+
+ // Create a thread with an ID > 1023 (the largest tid that can be stored in an
+ // object header)
+
+ List<Thread> threads = new List<Thread>(1024);
+ for (int i = 0; i < 1024; i++)
+ {
+ threads.Add(new Thread(delegate() { Assert(false, "this thread should never run"); }));
+ }
+ Thread highThread = new Thread(delegate()
+ {
+ Assert(Thread.CurrentThread.ManagedThreadId > 1024);
+ ContentionVariants();
+ });
+ highThread.Start();
+ highThread.Join();
+ }
+
+ int Run()
+ {
+ NegTests();
+ ContentionVariants();
+ ThreadIdPosTests();
+ return m_failed;
+ }
+
+ static int Main()
+ {
+ MonEnterTests tests = new MonEnterTests();
+ int failed = tests.Run();
+ if (0 != failed)
+ {
+ Console.WriteLine("Failed!");
+ }
+ else
+ {
+ Console.WriteLine("Success!");
+ }
+ return 100 + failed;
+ }
+}
+
diff --git a/tests/src/baseservices/threading/monitor/enter/monitorenter.csproj b/tests/src/baseservices/threading/monitor/enter/monitorenter.csproj
new file mode 100644
index 0000000000..6021171890
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/enter/monitorenter.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="MonitorEnter.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/isentered/app.config b/tests/src/baseservices/threading/monitor/isentered/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/isentered/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/monitor/isentered/monitorisentered.cs b/tests/src/baseservices/threading/monitor/isentered/monitorisentered.cs
new file mode 100644
index 0000000000..153359ea74
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/isentered/monitorisentered.cs
@@ -0,0 +1,128 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#define DEBUG //make sure the Contract calls actually do something
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Diagnostics.Contracts;
+
+
+public static class MonitorIsHeldTest
+{
+ static int s_result = 100;
+
+ static int Main()
+ {
+ try
+ {
+ RunNullTest();
+ RunTest(new object(), "object without SyncBlk");
+ RunTest(CreateObjectWithSyncBlk(), "object with SyncBlk");
+
+ Console.WriteLine(s_result == 100 ? "Success!" : "FAILED!");
+ return s_result;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Unhandled exception!");
+ Console.WriteLine(e);
+ return 999;
+ }
+ }
+
+ static object CreateObjectWithSyncBlk()
+ {
+ // force an object to have a SyncBlk, to exercise the IsEntered code that
+ // deals with these
+ object o = new object();
+ o.GetHashCode();
+ return o;
+ }
+
+ static void RunNullTest()
+ {
+ try
+ {
+ Monitor.IsEntered(null);
+ }
+ catch (ArgumentNullException)
+ {
+ // expected
+ return;
+ }
+
+ // no exception
+ Console.WriteLine("Monitor.IsEntered(null) did not throw ArgumentNullException");
+ s_result = 101;
+ }
+
+ static void RunTest(object obj, string caseName)
+ {
+ // lock not held by anyone
+ if (Monitor.IsEntered(obj))
+ {
+ Console.WriteLine("{0}: lock should be initially unheld, but IsEntered == true", caseName);
+ s_result = 102;
+ }
+
+ // lock held by this thread
+ lock (obj)
+ {
+ if (!Monitor.IsEntered(obj))
+ {
+ Console.WriteLine("{0}: lock should be held by this thread, but IsEntered == false", caseName);
+ s_result = 103;
+ }
+
+ // do it the way the user would
+ Contract.Assert(Monitor.IsEntered(obj));
+ }
+
+ // now it's released
+ if (Monitor.IsEntered(obj))
+ {
+ Console.WriteLine("{0}: lock should have been released, but IsEntered == true", caseName);
+ s_result = 104;
+ }
+
+ // do it the way the user would
+ Contract.Assert(!Monitor.IsEntered(obj));
+
+ // Make another thread hold the lock
+ ManualResetEventSlim lockHeldEvent = new ManualResetEventSlim();
+ ManualResetEventSlim releaseLockEvent = new ManualResetEventSlim();
+
+ Task otherThread = Task.Factory.StartNew(() =>
+ {
+ lock (obj)
+ {
+ Contract.Assert(Monitor.IsEntered(obj));
+ lockHeldEvent.Set();
+ releaseLockEvent.Wait();
+ }
+ });
+
+ lockHeldEvent.Wait();
+
+ // lock is held by other thread, so we should get "false"
+ if (Monitor.IsEntered(obj))
+ {
+ Console.WriteLine("{0}: lock should be held by other thread, but IsEntered == true", caseName);
+ s_result = 105;
+ }
+
+ releaseLockEvent.Set();
+ otherThread.Wait();
+
+ // lock is held by neither thread, so we should still get "false"
+ if (Monitor.IsEntered(obj))
+ {
+ Console.WriteLine("{0}: lock should not be held by any thread, but IsEntered == true", caseName);
+ s_result = 106;
+ }
+
+ }
+}
diff --git a/tests/src/baseservices/threading/monitor/isentered/monitorisentered.csproj b/tests/src/baseservices/threading/monitor/isentered/monitorisentered.csproj
new file mode 100644
index 0000000000..88b51ac8b1
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/isentered/monitorisentered.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="MonitorIsEntered.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/isentered/project.json b/tests/src/baseservices/threading/monitor/isentered/project.json
new file mode 100644
index 0000000000..3b0d4d7029
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/isentered/project.json
@@ -0,0 +1,34 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302",
+ "System.Diagnostics.Contracts": "4.0.0-beta-23127"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/pulse/monitorpulse02.cs b/tests/src/baseservices/threading/monitor/pulse/monitorpulse02.cs
new file mode 100644
index 0000000000..b8d8a86d50
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/pulse/monitorpulse02.cs
@@ -0,0 +1,55 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Reflection;
+using System.Threading;
+
+class Account
+{
+ public static void ThreadAbort(Thread thread)
+ {
+ MethodInfo abort = null;
+ foreach(MethodInfo m in thread.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
+ {
+ if (m.Name.Equals("AbortInternal") && m.GetParameters().Length == 0) abort = m;
+ }
+ if (abort == null)
+ {
+ throw new Exception("Failed to get Thread.Abort method");
+ }
+ abort.Invoke(thread, new object[0]);
+ }
+
+ private int balance = 0;
+ public void Deposit()
+ {
+ lock (this)
+ {
+ try { Monitor.Wait(this); }
+ catch(SynchronizationLockException) { }
+ finally { balance += 100; }
+ }
+ }
+ public static int Main()
+ {
+ int ret = 0;
+ Account a = new Account();
+ Thread t = new Thread(new ThreadStart(a.Deposit));
+ t.Start();
+ Thread.Sleep(100);
+ lock (a)
+ {
+ Console.WriteLine(a.balance); // Output: 0
+ Monitor.Pulse(a);
+ ThreadAbort(t);
+ Thread.Sleep(100);
+ if(a.balance == 0)
+ ret = 100;
+ Console.WriteLine(a.balance); // Output: 100.00 (bug)
+ }
+ Console.WriteLine(100 == ret ? "Test Passed" : "Test Failed");
+ return ret;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/pulse/monitorpulse02.csproj b/tests/src/baseservices/threading/monitor/pulse/monitorpulse02.csproj
new file mode 100644
index 0000000000..7c470fbf4a
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/pulse/monitorpulse02.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="MonitorPulse02.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/tryenter/app.config b/tests/src/baseservices/threading/monitor/tryenter/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/tryenter/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/monitor/tryenter/longtimeout.cs b/tests/src/baseservices/threading/monitor/tryenter/longtimeout.cs
new file mode 100644
index 0000000000..6e23ba5c3c
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/tryenter/longtimeout.cs
@@ -0,0 +1,92 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+using System.Threading;
+
+//Repro for VSWhidbey 565042
+
+public class Repro
+{
+ public static object _monitor = new Object();
+ private ManualResetEvent _event;
+ private ManualResetEvent _event2;
+ public static int _status = 1;
+
+ public static int Main(string[] arguments)
+ {
+ return (new Repro().RunTest());
+ }
+
+ public int RunTest()
+ {
+ _event = new ManualResetEvent(false);
+ _event2 = new ManualResetEvent(false);
+
+ Thread thread1 = new Thread(this.Thread1);
+ thread1.Start();
+
+ Thread thread2 = new Thread(this.Thread2);
+ thread2.Start();
+
+ thread2.Join();
+ _event2.Set();
+
+ if (_status == 100)
+ Console.WriteLine("Test Passed");
+ else
+ Console.WriteLine("Test Failed");
+
+ return _status;
+ }
+
+ private void Thread1()
+ {
+ Monitor.Enter(_monitor);
+ _event.Set();
+
+ _event2.WaitOne();
+ Monitor.Exit(_monitor);
+ }
+
+ private void Thread2()
+ {
+ Stopwatch timer = new Stopwatch();
+ _event.WaitOne();
+
+ timer.Start();
+ for (int i=10;i<=30;i=i+10)
+ {
+ bool tookLock = false;
+ Monitor.TryEnter(_monitor, TimeSpan.FromSeconds(i), ref tookLock);
+
+ if(tookLock)
+ {
+ _status = 98;
+ Console.WriteLine("TryEnter got monitor that it should not have been able to....");
+ Monitor.Exit(_monitor);
+ break;
+ }
+ else
+ {
+ timer.Stop();
+ if ((timer.Elapsed + TimeSpan.FromSeconds(1)) < TimeSpan.FromSeconds(i))
+ {
+ Console.WriteLine("TryEnter returned early in {0}, but expected {1}", timer.Elapsed, TimeSpan.FromSeconds(i));
+ _status = 99;
+ break;
+ }
+ else
+ {
+ Console.WriteLine("TryEnter returned as expected in {0}, with expected {1}", timer.Elapsed, TimeSpan.FromSeconds(i));
+ }
+ timer = Stopwatch.StartNew();
+ }
+ }
+
+ if (_status == 1)
+ _status=100;
+ }
+}
diff --git a/tests/src/baseservices/threading/monitor/tryenter/longtimeout.csproj b/tests/src/baseservices/threading/monitor/tryenter/longtimeout.csproj
new file mode 100644
index 0000000000..0f821945a3
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/tryenter/longtimeout.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="LongTimeOut.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/tryenter/negativetest.cs b/tests/src/baseservices/threading/monitor/tryenter/negativetest.cs
new file mode 100644
index 0000000000..2b1b3c344e
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/tryenter/negativetest.cs
@@ -0,0 +1,104 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Reflection;
+using System.Threading;
+
+
+public class OutOfRange
+{
+ Object lockMe;
+ Thread lockHolderThread;
+ AutoResetEvent inLock;
+
+ public static void ThreadAbort(Thread thread)
+ {
+ MethodInfo abort = null;
+ foreach(MethodInfo m in thread.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
+ {
+ if (m.Name.Equals("AbortInternal") && m.GetParameters().Length == 0) abort = m;
+ }
+ if (abort == null)
+ {
+ throw new Exception("Failed to get Thread.Abort method");
+ }
+ abort.Invoke(thread, new object[0]);
+ }
+
+ public OutOfRange(){
+ lockMe = new Object();
+ inLock = new AutoResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ OutOfRange oor = new OutOfRange();
+ int ret = oor.RunNegative(1);
+ ret += oor.RunNegative(2);
+ Console.WriteLine(ret/2 == 100 ? "Test Passed":"Test Failed");
+ return ret/2;
+ }
+
+
+ public int RunNegative(int test)
+ {
+ Console.WriteLine("Running Negative Test "+test);
+ int rValue = 0;
+ TimeSpan ts;
+
+ switch(test){
+ case 1:
+ Console.WriteLine("Int32.MaxValue + 1");
+ ts = new TimeSpan(21474836480000);
+ try{
+ Monitor.TryEnter(lockMe,ts);
+ }
+ catch(ArgumentOutOfRangeException)
+ {
+ rValue = 100;
+ }
+ break;
+
+ case 2:
+ Console.WriteLine("TimeSpan(-2)");
+ ts = new TimeSpan(-20000);
+ Console.WriteLine(ts.TotalMilliseconds);
+ NewThreadHoldLock();
+ try{
+ Monitor.TryEnter(lockMe,ts);
+ }
+ catch(ArgumentOutOfRangeException)
+ {
+ rValue = 100;
+ }
+ AbortLockHolderThread();
+ break;
+
+ }
+ return rValue;
+ }
+
+ private void AbortLockHolderThread()
+ {
+ ThreadAbort(lockHolderThread);
+ }
+
+ private void NewThreadHoldLock()
+ {
+ lockHolderThread = new Thread(new ParameterizedThreadStart(HoldLock));
+ lockHolderThread.Start(lockMe);
+ inLock.WaitOne();
+
+ }
+ private void HoldLock(object foo)
+ {
+ lock(foo)
+ {
+ inLock.Set();
+ Thread.Sleep(-1);
+ }
+ }
+}
+
diff --git a/tests/src/baseservices/threading/monitor/tryenter/negativetestharness.csproj b/tests/src/baseservices/threading/monitor/tryenter/negativetestharness.csproj
new file mode 100644
index 0000000000..56c4e20daf
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/tryenter/negativetestharness.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="NegativeTest.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/tryenter/project.json b/tests/src/baseservices/threading/monitor/tryenter/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/tryenter/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/wait/app.config b/tests/src/baseservices/threading/monitor/wait/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/wait/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/monitor/wait/project.json b/tests/src/baseservices/threading/monitor/wait/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/wait/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/monitor/wait/waitnull.cs b/tests/src/baseservices/threading/monitor/wait/waitnull.cs
new file mode 100644
index 0000000000..e2748257d0
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/wait/waitnull.cs
@@ -0,0 +1,26 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class Test
+{
+
+ public static int Main()
+ {
+ try
+ {
+ Monitor.Wait(null, 0);
+ Console.WriteLine("Failed to throw exception on Monitor.Wait");
+ return 1;
+ }
+ catch(ArgumentNullException)
+ {
+ //Expected
+ }
+ return 100;
+ }
+}
+
diff --git a/tests/src/baseservices/threading/monitor/wait/waitnull.csproj b/tests/src/baseservices/threading/monitor/wait/waitnull.csproj
new file mode 100644
index 0000000000..bcbccdf971
--- /dev/null
+++ b/tests/src/baseservices/threading/monitor/wait/waitnull.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitNull.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/multiinstance/app.config b/tests/src/baseservices/threading/multiinstance/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/multiinstance/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/multiinstance/multiinstance.cs b/tests/src/baseservices/threading/multiinstance/multiinstance.cs
new file mode 100644
index 0000000000..0238fd821d
--- /dev/null
+++ b/tests/src/baseservices/threading/multiinstance/multiinstance.cs
@@ -0,0 +1,322 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.IO;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Security;
+using System.Threading;
+using System.Collections.Generic;
+using TestLibrary;
+
+#if WINCORESYS
+[assembly: AllowPartiallyTrustedCallers]
+#endif
+
+[SecuritySafeCritical]
+public class MultiThreading
+{
+ #region ParamsDefintion
+ private struct CommandLineParams
+ {
+ public string assemblyName;
+ public string[] args;
+ public int workers;
+ }
+ #endregion Params
+
+ #region Data
+ static private CommandLineParams cmdParams;
+ static private MethodInfo methToExec;
+ static private List<int> retVals;
+ static private object myLock;
+ static private ManualResetEvent[] events;
+ #endregion Data
+
+
+ #region Utilities
+ private static void Usage()
+ {
+ Console.WriteLine("Usage: MultipleInstance.exe /workers:#### /exe:#####");
+ Console.WriteLine("/workers: run test in n threads.");
+ }
+
+ private static bool ParseArguments(string[] args, ref CommandLineParams cmdParams)
+ {
+ bool ret = true;
+ cmdParams.workers = 0;
+ try
+ {
+ int index = 0;
+ for (int i = 0; i < args.Length; i++)
+ {
+ string name = "";
+ string value = "";
+
+ if (args[i].Contains(":"))
+ {
+ name = args[i].Substring(0, args[i].IndexOf(":")).ToLower();
+ value = args[i].Substring(args[i].IndexOf(":") + 1);
+ }
+
+ if (name.StartsWith("/workers"))
+ {
+ cmdParams.workers = Convert.ToInt32(value);
+ }
+ else if (name.StartsWith("/exe"))
+ {
+ cmdParams.assemblyName = value;
+ index = i;
+ break;
+ }
+ else
+ {
+ Console.WriteLine("Invalid paramter: {0}", args[i]);
+ ret = false;
+ }
+ }
+ if (index == args.Length - 1)
+ {
+ cmdParams.args = new string[0];
+ }
+ else
+ {
+ cmdParams.args = new string[args.Length - index - 1];
+ for (int i = index + 1; i < args.Length; i++)
+ {
+ cmdParams.args[i - index - 1] = args[i];
+ }
+ }
+
+
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.ToString());
+ ret = false;
+ }
+ return ret;
+ }
+
+ public static Byte[] ReadFileContents(String path)
+ {
+ byte[] bytes;
+ using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
+ {
+ // Do a blocking read
+ int index = 0;
+ long fileLength = fs.Length;
+ if (fileLength > Int32.MaxValue)
+ throw new IOException("File size greater then 2Gb");
+ int count = (int)fs.Length;
+ bytes = new byte[count];
+ while (count > 0)
+ {
+ int n = fs.Read(bytes, index, count);
+ if (n == 0)
+ throw new EndOfStreamException();
+ index += n;
+ count -= n;
+ }
+ }
+ return bytes;
+ }
+
+ private static MethodInfo GetEntryPoint(string assemblyName)
+ {
+ Assembly asm = null;
+ string asmName = "";
+
+
+ asmName = assemblyName;
+
+ try
+ {
+ asmName = assemblyName;
+ if (asmName.LastIndexOf(".") > -1)
+ {
+ asmName = asmName.Substring(0, asmName.LastIndexOf("."));
+ }
+ if (asmName.LastIndexOf(@"\") > -1)
+ {
+ asmName = asmName.Substring(asmName.LastIndexOf(@"\") + 1);
+ }
+ if (asmName.LastIndexOf(@"/") > -1)
+ {
+ asmName = asmName.Substring(asmName.LastIndexOf(@"/") + 1);
+ }
+
+ asm = Assembly.Load( new AssemblyName(asmName) );
+ }
+ catch (FileLoadException)
+ {
+ asm = null;
+ }
+ catch (FileNotFoundException)
+ {
+ asm = null;
+ }
+
+ if (null == asm)
+ {
+ MethodInfo assemload = null;
+ foreach(MethodInfo m in typeof(Assembly).GetMethods(BindingFlags.NonPublic | BindingFlags.Static))
+ {
+ ParameterInfo[] mps = m.GetParameters();
+ if (m.Name.Equals("Load") && mps.Length == 1 && mps[0].GetType() == typeof(byte[])) assemload = m;
+ }
+ if (assemload == null) {
+ throw new Exception("Failed to get Assembly.Load(int8[]) method");
+ }
+
+ asm = (Assembly)assemload.Invoke(null, new object[1] { ReadFileContents( assemblyName ) });
+ }
+
+ methToExec = asm.EntryPoint;
+
+ return methToExec;
+ }
+
+ private static void Worker()
+ {
+ if (cmdParams.workers > 1)
+ WaitHandle.WaitAny(events);
+
+ RunMain();
+ }
+
+ private static Thread NewThread()
+ {
+ Thread t = null;
+ t = new Thread(new ThreadStart(Worker));
+ return t;
+ }
+ #endregion Utilities
+
+ #region Main
+ public static int Main(string[] args)
+ {
+ if (0 == args.Length)
+ {
+ Usage();
+ return 0;
+ }
+
+ cmdParams = new CommandLineParams();
+ if (!ParseArguments(args, ref cmdParams))
+ {
+ Usage();
+ return 0;
+ }
+
+ retVals = new List<int>();
+ myLock = new object();
+
+ Run(); //run test...
+
+ int retVal = retVals[0];
+ for (int i = 0; i < retVals.Count - 1; i++)
+ {
+ if (retVals[i] != retVals[i + 1])
+ {
+ Logging.WriteLine("Failed");
+ retVal = 0xff;
+ break;
+ }
+ }
+ return retVal;
+ }
+
+ private static void Run()
+ {
+ methToExec = GetEntryPoint(cmdParams.assemblyName);
+ int threadNum = cmdParams.workers;
+ if (threadNum == 0)
+ {
+ Logging.WriteLine("Run test in the main thread");
+ RunMain();
+ }
+ else if (threadNum == 1)
+ {
+ Logging.WriteLine("Run test in a worker thread");
+ Thread t = NewThread();
+ t.Start();
+ t.Join();
+ }
+ else if (threadNum > 1)
+ {
+ Logging.WriteLine("Run test in the main thread and spawn {0} threads to run test", threadNum - 1);
+
+ events = new ManualResetEvent[1];
+ events[0] = new ManualResetEvent(false);
+
+ Thread[] threads = new Thread[threadNum - 1];
+ for (int i = 0; i < threads.Length; i++)
+ {
+ threads[i] = NewThread();
+ threads[i].Start();
+ }
+ events[0].Set();
+ RunMain();
+ foreach (Thread t in threads)
+ {
+ t.Join();
+ }
+ }
+ }
+
+
+
+
+ private static void RunMain()
+ {
+ int numMainParams = methToExec.GetParameters().Length;
+ if (numMainParams > 1)
+ {
+ throw new Exception("Main method must contain 0 or 1 arguments.");
+ }
+
+ DateTime time1 = DateTime.Now;
+ Object oExitCode = null;
+ while (true)
+ {
+ oExitCode = methToExec.Invoke(null, numMainParams == 1 ? new Object[] { cmdParams.args } : null);
+ DateTime time2 = DateTime.Now;
+ TimeSpan span = time2 - time1;
+ if (span.TotalMilliseconds > 1500)
+ break;
+ Thread.Sleep(0);
+ }
+
+
+ int iRetCode;
+ if (methToExec.ReturnParameter.ParameterType == typeof(void))
+ {
+ //iRetCode = Environment.ExitCode;
+ Console.WriteLine("WARNING: Unable to get the exit code from a void Main method");
+ iRetCode = 100;
+ }
+ else if (methToExec.ReturnParameter.ParameterType == typeof(int))
+ {
+ iRetCode = (int)oExitCode;
+ }
+ else if (methToExec.ReturnParameter.ParameterType == typeof(uint))
+ {
+ iRetCode = (int)(uint)oExitCode;
+ }
+ else
+ {
+ throw new Exception("Main method must return void, int or uint not " + methToExec.ReturnParameter.ParameterType.ToString());
+ }
+
+ lock (myLock)
+ {
+ retVals.Add(iRetCode);
+ }
+ }
+ #endregion
+}
+
+
diff --git a/tests/src/baseservices/threading/multiinstance/multiinstance.csproj b/tests/src/baseservices/threading/multiinstance/multiinstance.csproj
new file mode 100644
index 0000000000..16ce01a17f
--- /dev/null
+++ b/tests/src/baseservices/threading/multiinstance/multiinstance.csproj
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestKind>BuildOnly</CLRTestKind>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="MultiInstance.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/multiinstance/project.json b/tests/src/baseservices/threading/multiinstance/project.json
new file mode 100644
index 0000000000..cd852c657d
--- /dev/null
+++ b/tests/src/baseservices/threading/multiinstance/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.1.0-beta-23516",
+ "System.Reflection.Primitives": "4.0.1-beta-23516",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am01waitallneg.cs b/tests/src/baseservices/threading/mutex/abandonedmutex/am01waitallneg.cs
new file mode 100644
index 0000000000..c3f68a22ce
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am01waitallneg.cs
@@ -0,0 +1,52 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private Mutex myMutex01 = new Mutex(false);
+ private Mutex myMutex02 = new Mutex(false);
+ private Mutex myMutex03 = new Mutex(false);
+ private ManualResetEvent myMRE = new ManualResetEvent(false);
+ private int iRet = -1;
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ wae.Run();
+ Console.WriteLine(wae.iRet == 100 ? "Test Passed!" : "Test Failed");
+ return wae.iRet;
+ }
+
+ private void Run()
+ {
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ myMRE.WaitOne();
+
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(
+ new WaitHandle[]{myMutex01, myMutex02, myMutex03}, 5000);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException am)
+ {
+ Console.WriteLine("AbandonedMutexException thrown! Checking values...");
+ if(-1 == am.MutexIndex && null == am.Mutex)
+ iRet = 100;
+ }
+ }
+
+ private void AbandonTheMutex()
+ {
+ myMutex03.WaitOne();
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am01waitallneg.csproj b/tests/src/baseservices/threading/mutex/abandonedmutex/am01waitallneg.csproj
new file mode 100644
index 0000000000..fc48cfd807
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am01waitallneg.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="AM01WaitAllNeg.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am02waitoneneg.cs b/tests/src/baseservices/threading/mutex/abandonedmutex/am02waitoneneg.cs
new file mode 100644
index 0000000000..4dc5171717
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am02waitoneneg.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+ private int iRet = -1;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex(false);
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ wao.Run();
+ Console.WriteLine(100 == wao.iRet ? "Test Passed" : "Test Failed");
+ return wao.iRet;
+ }
+
+ private void Run()
+ {
+ Console.WriteLine("Test abandoned mutex is thrown using WaitOne");
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bool bRet = myMutex.WaitOne(10000);
+ Console.WriteLine("WaitOne did not throw an exception!");
+ }
+ catch(AbandonedMutexException am)
+ {
+ Console.WriteLine("AbandonedMutexException thrown! Checking values...");
+ if(-1 == am.MutexIndex && null == am.Mutex)
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am02waitoneneg.csproj b/tests/src/baseservices/threading/mutex/abandonedmutex/am02waitoneneg.csproj
new file mode 100644
index 0000000000..8437995a9b
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am02waitoneneg.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="AM02WaitOneNeg.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am04waitany.cs b/tests/src/baseservices/threading/mutex/abandonedmutex/am04waitany.cs
new file mode 100644
index 0000000000..377d27d68a
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am04waitany.cs
@@ -0,0 +1,113 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ private int iRet = -1;
+ private ManualResetEvent mre = new ManualResetEvent(false);
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: AM04WaitAny /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAnyEx wae = new WaitAnyEx();
+ wae.Run(iSize, iPos);
+
+ Console.WriteLine(100 == wae.iRet ? "Test Passed" : "Test Failed");
+ return wae.iRet;
+ }
+
+ private void Run(int iArraySize, int iPosToAbandon)
+ {
+ Console.WriteLine("Abandon a particular mutex - " + iArraySize + ", " +
+ iPosToAbandon);
+ CreateMutexArray(iArraySize, iPosToAbandon);
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(iPosToAbandon);
+ mre.WaitOne();
+ int i = -1;
+
+ try
+ {
+ Console.WriteLine("Waiting...");
+ i = WaitHandle.WaitAny(wh, -1);
+ }
+ catch(AbandonedMutexException am)
+ {
+ Console.WriteLine("AbandonedMutexException thrown! Checking values...");
+ if(iPosToAbandon == am.MutexIndex && wh[am.MutexIndex] == am.Mutex)
+ iRet = 50;
+
+ // We should now be in a state where this thread owns the mutex
+ am.Mutex.WaitOne();
+ am.Mutex.ReleaseMutex();
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ t.Join();
+
+ // Release a 2nd time
+ try
+ {
+ Console.WriteLine("Release again");
+ ((Mutex)wh[iPosToAbandon]).ReleaseMutex();
+ iRet += 50;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ mre.Set();
+ }
+
+ private void CreateMutexArray(int numElements, int iPos)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ if(i != iPos)
+ wh[i] = new AutoResetEvent(false);
+ else
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am04waitany.csproj b/tests/src/baseservices/threading/mutex/abandonedmutex/am04waitany.csproj
new file mode 100644
index 0000000000..956b896884
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am04waitany.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:10 /pos:0</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="AM04WaitAny.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am05waitanymutex.cs b/tests/src/baseservices/threading/mutex/abandonedmutex/am05waitanymutex.cs
new file mode 100644
index 0000000000..0f093d8b41
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am05waitanymutex.cs
@@ -0,0 +1,112 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ private int iRet = -1;
+ private ManualResetEvent mre = new ManualResetEvent(false);
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: AM05WaitAny /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAnyEx wae = new WaitAnyEx();
+ wae.Run(iSize, iPos);
+
+ Console.WriteLine(100 == wae.iRet ? "Test Passed" : "Test Failed");
+ return wae.iRet;
+ }
+
+ private void Run(int iArraySize, int iPosToAbandon)
+ {
+ Console.WriteLine("Abandon a particular mutex - " + iArraySize + ", " +
+ iPosToAbandon);
+ CreateMutexArray(iArraySize);
+
+ Thread t2 = new Thread(new ParameterizedThreadStart(this.AbandonElse));
+ t2.Start(iPosToAbandon);
+
+ // Let the thread work
+ Thread.Sleep(1000);
+
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(iPosToAbandon);
+ mre.WaitOne();
+ int i = -1;
+
+ try
+ {
+ Console.WriteLine("Waiting...");
+ i = WaitHandle.WaitAny(wh, -1);
+ Console.WriteLine("No exception thrown - " + i);
+ }
+ catch(AbandonedMutexException am)
+ {
+ Console.WriteLine("AbandonedMutexException thrown! Checking values...");
+ if(iPosToAbandon == am.MutexIndex && wh[am.MutexIndex] == am.Mutex)
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ }
+
+ private void AbandonElse(Object o)
+ {
+ // Do a wait on all of them so it blocks WaitAny()
+ for(int i=0;i<wh.Length;i++)
+ {
+ if(i != Convert.ToInt32(o))
+ wh[i].WaitOne();
+ }
+ mre.WaitOne();
+ Thread.Sleep(5000);
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ mre.Set();
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am05waitanymutex.csproj b/tests/src/baseservices/threading/mutex/abandonedmutex/am05waitanymutex.csproj
new file mode 100644
index 0000000000..706d6f5114
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am05waitanymutex.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:64 /pos:63</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="AM05WaitAnyMutex.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am06abandonall.cs b/tests/src/baseservices/threading/mutex/abandonedmutex/am06abandonall.cs
new file mode 100644
index 0000000000..650dcb0dd6
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am06abandonall.cs
@@ -0,0 +1,70 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon all mutexes in array");
+ CreateMutexArray(64);
+ myMRE = new ManualResetEvent(false);
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexes));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh, 10000);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException am)
+ {
+ Console.WriteLine("AbandonedMutexException thrown! Checking values...");
+ if(am.MutexIndex == 0 && am.Mutex == wh[am.MutexIndex])
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexes()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am06abandonall.csproj b/tests/src/baseservices/threading/mutex/abandonedmutex/am06abandonall.csproj
new file mode 100644
index 0000000000..5e4b32bd06
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am06abandonall.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="AM06AbandonAll.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am07abandonmultiplemutex.cs b/tests/src/baseservices/threading/mutex/abandonedmutex/am07abandonmultiplemutex.cs
new file mode 100644
index 0000000000..f4e6d4a40b
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am07abandonmultiplemutex.cs
@@ -0,0 +1,96 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ private int iRet = -1;
+ private ManualResetEvent mre = new ManualResetEvent(false);
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ wae.Run();
+
+ Console.WriteLine(100 == wae.iRet ? "Test Passed" : "Test Failed");
+ return wae.iRet;
+ }
+
+ private void Run()
+ {
+ CreateMutexArray(64);
+ int[] aPos = new int[5]{6,8,10,12,14};
+ Thread t2 = new Thread(new ParameterizedThreadStart(this.AbandonElse));
+ t2.Start(aPos[0]);
+
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(aPos);
+ mre.WaitOne();
+ int i = -1;
+ Thread.Sleep(400);
+
+ try
+ {
+ Console.WriteLine("Waiting...");
+ i = WaitHandle.WaitAny(wh, -1);
+ Console.WriteLine("No exception thrown - {0}", i);
+ }
+ catch(AbandonedMutexException am)
+ {
+ Console.WriteLine("AbandonedMutexException thrown! Checking values...");
+ if(aPos[0] == am.MutexIndex && wh[am.MutexIndex] == am.Mutex)
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ t.Join();
+ }
+
+ private void AbandonElse(Object o)
+ {
+ int iPos = (int)o;
+
+ // Do a wait on all Mutexes up to the 1st one
+ for(int i=0;i<iPos;i++)
+ {
+ wh[i].WaitOne();
+ Console.WriteLine("Blocking {0}", i);
+ }
+
+ mre.WaitOne();
+ Thread.Sleep(5000);
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ // This thread needs to complete before the wait
+ // otherwise the Wait will return immediately
+
+ int[] iPos = (int[])o;
+ for(int i=0;i<iPos.Length;i++)
+ {
+ wh[iPos[i]].WaitOne();
+ Console.WriteLine(iPos[i]);
+ }
+ mre.Set();
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am07abandonmultiplemutex.csproj b/tests/src/baseservices/threading/mutex/abandonedmutex/am07abandonmultiplemutex.csproj
new file mode 100644
index 0000000000..1e29163c91
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am07abandonmultiplemutex.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="AM07AbandonMultipleMutex.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am08mixedarray.cs b/tests/src/baseservices/threading/mutex/abandonedmutex/am08mixedarray.cs
new file mode 100644
index 0000000000..b61f42c665
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am08mixedarray.cs
@@ -0,0 +1,119 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ ManualResetEvent mre = new ManualResetEvent(false);
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning only one Mutex in array with other WaitHandles, signaling other mutexes");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.WaitOnAllExceptPos));
+ t.Start();
+
+ Thread t2 = new Thread(new ThreadStart(this.AbandonLastMutex));
+ t2.Start();
+
+ mre.WaitOne();
+ mre.Reset();
+ t2.Join(); // make sure the thread has exited before checking for the abandoned mutex
+
+ int i = -1;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ i = WaitHandle.WaitAny(wh, 5000);
+ Console.WriteLine("WaitAny did not throw AbandonedMutexExcpetion");
+ Console.WriteLine("Object at position {0} ({1}) returned", i, wh[i].GetType());
+ }
+ catch(AbandonedMutexException am)
+ {
+ Console.WriteLine("AbandonedMutexException thrown! Checking values...");
+ if(61 == am.MutexIndex)
+ {
+ if (am.Mutex == wh[am.MutexIndex])
+ iRet = 100;
+ else
+ Console.WriteLine("Expected AbandonedMutexException to == Indexed Mutex, but it does not.");
+ }
+ else
+ Console.WriteLine("Expected return of 61, but found " + am.MutexIndex);
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void WaitOnAllExceptPos()
+ {
+ Mutex m = new Mutex();
+ bool bSet = false;
+ for(int i=wh.Length-1;i>=0;i--)
+ {
+ if(wh[i].GetType() == m.GetType())
+ {
+ if(bSet)
+ {
+ wh[i].WaitOne();
+ Console.Write(i + ".");
+ }
+ bSet = true;
+ }
+ }
+ mre.Set();
+ //This Sleep keeps Thread alive to hold Mutexes
+ Thread.Sleep(15000);
+ }
+
+ private void AbandonLastMutex()
+ {
+ Mutex m = new Mutex();
+ for(int i=wh.Length-1;i>=0;i--)
+ {
+ if(wh[i].GetType() == m.GetType())
+ {
+ wh[i].WaitOne();
+ Console.WriteLine(i + "AbandonLastMutex.");
+ break;
+ }
+ }
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%3)
+ {
+ case 0:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ break;
+ case 2:
+ wh[i] = new Semaphore(0,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am08mixedarray.csproj b/tests/src/baseservices/threading/mutex/abandonedmutex/am08mixedarray.csproj
new file mode 100644
index 0000000000..6b61d26474
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am08mixedarray.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="AM08MixedArray.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am09threadabort.cs b/tests/src/baseservices/threading/mutex/abandonedmutex/am09threadabort.cs
new file mode 100644
index 0000000000..a8ba27b35d
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am09threadabort.cs
@@ -0,0 +1,71 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Reflection;
+using System.Threading;
+
+class WaitAllEx
+{
+ private Mutex myMutex01 = new Mutex(false, Common.GetUniqueName());
+ private Mutex myMutex02 = new Mutex(false, Common.GetUniqueName());
+ private Mutex myMutex03 = new Mutex(false, Common.GetUniqueName());
+ private ManualResetEvent myMRE = new ManualResetEvent(false);
+ private int iRet = -1;
+
+ private static void ThreadAbort(Thread thread)
+ {
+ MethodInfo abort = null;
+ foreach(MethodInfo m in thread.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
+ {
+ if (m.Name.Equals("AbortInternal") && m.GetParameters().Length == 0) abort = m;
+ }
+ if (abort == null)
+ {
+ throw new Exception("Failed to get Thread.Abort method");
+ }
+ abort.Invoke(thread, new object[0]);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ wae.Run();
+ Console.WriteLine(wae.iRet == 100 ? "Test Passed!" : "Test Failed");
+ return wae.iRet;
+ }
+
+ private void Run()
+ {
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ myMRE.WaitOne();
+ Thread.Sleep(500);
+ ThreadAbort(t);
+
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int ret = WaitHandle.WaitAny(
+ new WaitHandle[]{myMutex01, myMutex02, myMutex03}, 5000);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, return = " + ret);
+ }
+ catch(AbandonedMutexException am)
+ {
+ Console.WriteLine("AbandonedMutexException thrown! Checking values...");
+ if(0 == am.MutexIndex && myMutex01 == am.Mutex)
+ iRet = 100;
+ }
+ }
+
+ private void AbandonTheMutex()
+ {
+ myMutex01.WaitOne();
+ myMutex02.WaitOne();
+ myMutex03.WaitOne();
+ myMRE.Set();
+ Thread.Sleep(10000);
+ }
+}
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/am09threadabort.csproj b/tests/src/baseservices/threading/mutex/abandonedmutex/am09threadabort.csproj
new file mode 100644
index 0000000000..60f716f530
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/am09threadabort.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="AM09ThreadAbort.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/app.config b/tests/src/baseservices/threading/mutex/abandonedmutex/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/mutex/abandonedmutex/project.json b/tests/src/baseservices/threading/mutex/abandonedmutex/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/abandonedmutex/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/misc/app.config b/tests/src/baseservices/threading/mutex/misc/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/mutex/misc/mutexctor1.cs b/tests/src/baseservices/threading/mutex/misc/mutexctor1.cs
new file mode 100644
index 0000000000..e82bb26c37
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/mutexctor1.cs
@@ -0,0 +1,173 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading; // For Thread, Mutex
+
+/// <summary>
+/// Ctor(Boolean)
+/// </summary>
+///
+// Tests that you can create a mutex, that if the mutex is
+// owned that other threads cannot change shared state governed
+// by that mutex, and that if it is unowned we can pick it up
+// without blocking.
+public class MutexCtor1
+{
+ #region Public Fields
+ public const int c_DEFAULT_INT_VALUE = 0;
+
+ public volatile static int m_SharedResource = c_DEFAULT_INT_VALUE;
+ #endregion
+
+ #region Private Fields
+ private const int c_DEFAULT_SLEEP_TIME = 1000; // 1 second
+
+ private Mutex m_Mutex = null;
+ #endregion
+
+ #region Public Methods
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+ retVal = PosTest2() && retVal;
+
+ return retVal;
+ }
+
+ #region Positive Test Cases
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ // Add your scenario description here
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Construct a new Mutex instance with initiallyOwned set to true (ensure that the thread owns the mutex)");
+
+ using(m_Mutex = new Mutex(true))
+ {
+ try
+ {
+ do
+ {
+ if (null == m_Mutex)
+ {
+ TestLibrary.TestFramework.LogError("001", "Can not construct a new Mutex intance with initiallyOwned set to true.");
+ retVal = false;
+
+ break;
+ }
+
+ // Ensure initial owner of the mutex is current thread
+
+ // Create another thread to change value of m_SharedResource
+ thread = new Thread(new ThreadStart(ThreadProc));
+ thread.Start();
+
+ // Sleep 1 second to wait the thread get started
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+
+ if (m_SharedResource != c_DEFAULT_INT_VALUE)
+ {
+ TestLibrary.TestFramework.LogError("002", "Call Mutex(true) does not set current thread to be the owner of the mutex.");
+ retVal = false;
+ }
+ m_Mutex.ReleaseMutex();
+ } while (false); // do
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ if (null != thread)
+ {
+ // Wait until all threads are terminated
+ thread.Join();
+ }
+
+ // Reset the value of m_SharedResource for further usage
+ m_SharedResource = c_DEFAULT_INT_VALUE;
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest2()
+ {
+ bool retVal = true;
+
+ // Add your scenario description here
+ TestLibrary.TestFramework.BeginScenario("PosTest2: Construct a new Mutex instance with initiallyOwned set to false. Ensure that the thread does not own the mutex");
+
+ using (m_Mutex = new Mutex(false))
+ {
+ try
+ {
+ if (null == m_Mutex)
+ {
+ TestLibrary.TestFramework.LogError("004", "Can not construct a new Mutex intance with initiallyOwned set to false.");
+ retVal = false;
+ }
+ else
+ {
+ // this would block this thread if we owned the mutex
+ m_Mutex.WaitOne();
+ m_Mutex.ReleaseMutex();
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Reset the value of m_SharedResource for further usage
+ m_SharedResource = c_DEFAULT_INT_VALUE;
+ }
+ }
+
+ return retVal;
+ }
+ #endregion
+ #endregion
+
+ public static int Main()
+ {
+ MutexCtor1 test = new MutexCtor1();
+
+ TestLibrary.TestFramework.BeginTestCase("MutexCtor1");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ #region Private Methods
+ private void ThreadProc()
+ {
+ m_Mutex.WaitOne();
+ m_SharedResource++;
+ m_Mutex.ReleaseMutex();
+ }
+ #endregion
+}
diff --git a/tests/src/baseservices/threading/mutex/misc/mutexctor1.csproj b/tests/src/baseservices/threading/mutex/misc/mutexctor1.csproj
new file mode 100644
index 0000000000..08d163251e
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/mutexctor1.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="MutexCtor1.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/misc/mutexctor2.cs b/tests/src/baseservices/threading/mutex/misc/mutexctor2.cs
new file mode 100644
index 0000000000..0dff03ec8c
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/mutexctor2.cs
@@ -0,0 +1,104 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading; // For Thread, Mutex
+
+/// <summary>
+/// Ctor()
+/// </summary>
+///
+// tests the default mutex constructor creates
+// a mutex which is not owned.
+public class MutexCtor2
+{
+ #region Public Fields
+ public const int c_DEFAULT_INT_VALUE = 0;
+
+ public static int m_SharedResource = c_DEFAULT_INT_VALUE;
+ #endregion
+
+ #region Private Fields
+ private Mutex m_Mutex = null;
+ #endregion
+
+ #region Public Methods
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ return retVal;
+ }
+
+ #region Positive Test Cases
+ public bool PosTest1()
+ {
+ bool retVal = true;
+
+ // Add your scenario description here
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Construct a new Mutex instance");
+
+ // create the mutex in unowned state
+ using (m_Mutex = new Mutex())
+ {
+ try
+ {
+ do
+ {
+ if (null == m_Mutex)
+ {
+ TestLibrary.TestFramework.LogError("001", "Can not construct a new Mutex intance");
+ retVal = false;
+
+ break;
+ }
+
+ // Ensure initial owner of the mutex is not the current thread
+ // This call should NOT block
+ m_Mutex.WaitOne();
+ m_Mutex.ReleaseMutex();
+
+ } while (false); // do
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Reset the value of m_SharedResource for further usage
+ m_SharedResource = c_DEFAULT_INT_VALUE;
+ }
+ }
+
+ return retVal;
+ }
+ #endregion
+ #endregion
+
+ public static int Main()
+ {
+ MutexCtor2 test = new MutexCtor2();
+
+ TestLibrary.TestFramework.BeginTestCase("MutexCtor2");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/mutex/misc/mutexctor2.csproj b/tests/src/baseservices/threading/mutex/misc/mutexctor2.csproj
new file mode 100644
index 0000000000..537f73b806
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/mutexctor2.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="MutexCtor2.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/misc/project.json b/tests/src/baseservices/threading/mutex/misc/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/misc/waitone1.cs b/tests/src/baseservices/threading/mutex/misc/waitone1.cs
new file mode 100644
index 0000000000..40f144b66b
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/waitone1.cs
@@ -0,0 +1,217 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading; // For Thread, Mutex
+
+/// <summary>
+/// WaitOne()
+/// </summary>
+///
+// Tests that Mutex.WaitOne will block when another
+// thread holds the mutex, and then will grab the mutex
+// when it is released. Also that appropriate exceptions
+// are thrown if the other thread abandons or disposes of
+// the mutex
+public class MutexWaitOne1
+{
+ #region Private Fields
+ private const int c_DEFAULT_SLEEP_TIME = 1000; // 1 second
+
+ private Mutex m_Mutex = null;
+ #endregion
+
+ #region Public Methods
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ TestLibrary.TestFramework.LogInformation("[Negative]");
+ retVal = NegTest1() && retVal;
+ retVal = NegTest2() && retVal;
+
+ return retVal;
+ }
+
+ #region Positive Test Cases
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: WaitOne returns true when current instance receives a signal");
+
+ try
+ {
+ do
+ {
+ m_Mutex = new Mutex();
+ thread = new Thread(new ThreadStart(SignalMutex));
+ thread.Start();
+
+ if (m_Mutex.WaitOne() != true)
+ {
+ TestLibrary.TestFramework.LogError("001", "WaitOne returns false when current instance receives a signal.");
+ retVal = false;
+
+ break;
+ }
+
+ m_Mutex.ReleaseMutex();
+ } while (false); // do
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Wait for the thread to terminate
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ m_Mutex.Dispose();
+ }
+
+ return retVal;
+ }
+ #endregion
+
+ #region Negative Test Cases
+ public bool NegTest1()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("NegTest1: AbandonedMutexException should be thrown if a thread exited without releasing a mutex");
+
+ using (m_Mutex = new Mutex(false))
+ {
+ try
+ {
+ thread = new Thread(new ThreadStart(NeverReleaseMutex));
+ thread.Start();
+
+ Thread.Sleep(100);
+ m_Mutex.WaitOne();
+
+ TestLibrary.TestFramework.LogError("101", "AbandonedMutexException is not thrown if a thread exited without releasing a mutex");
+ retVal = false;
+ }
+ catch (AbandonedMutexException)
+ {
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ if (null != thread)
+ {
+ thread.Join();
+ }
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool NegTest2()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("NegTest2: ObjectDisposedException should be thrown if current instance has already been disposed");
+
+ try
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(DisposeMutex));
+ thread.Start();
+
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ m_Mutex.WaitOne();
+
+ TestLibrary.TestFramework.LogError("103", "ObjectDisposedException is not thrown if current instance has already been disposed");
+ retVal = false;
+ }
+ catch (ObjectDisposedException)
+ {
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ ((IDisposable)m_Mutex).Dispose();
+ }
+ }
+
+ return retVal;
+ }
+ #endregion
+ #endregion
+
+ public static int Main()
+ {
+ MutexWaitOne1 test = new MutexWaitOne1();
+
+ TestLibrary.TestFramework.BeginTestCase("MutexWaitOne1");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ #region Private Methods
+ private void SignalMutex()
+ {
+ m_Mutex.WaitOne();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ m_Mutex.ReleaseMutex();
+ }
+
+ private void NeverReleaseMutex()
+ {
+ m_Mutex.WaitOne();
+ // Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ }
+
+ private void DisposeMutex()
+ {
+ // Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ ((IDisposable)m_Mutex).Dispose();
+ }
+ #endregion
+}
diff --git a/tests/src/baseservices/threading/mutex/misc/waitone1.csproj b/tests/src/baseservices/threading/mutex/misc/waitone1.csproj
new file mode 100644
index 0000000000..d182b6f327
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/waitone1.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOne1.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/misc/waitone2.cs b/tests/src/baseservices/threading/mutex/misc/waitone2.cs
new file mode 100644
index 0000000000..8c0a94d5a8
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/waitone2.cs
@@ -0,0 +1,573 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading; // For Thread, Mutex
+
+public class TestContextBoundObject
+{
+ public void TestMethod()
+ {
+ Thread.Sleep(MutexWaitOne2.c_LONG_SLEEP_TIME);
+ }
+}
+
+/// <summary>
+/// WaitOne(System.Int32, System.Boolean)
+/// </summary>
+///
+
+// Exercises Mutex:
+// Waits infinitely,
+// Waits a finite time,
+// Times out appropriately,
+// Throws Exceptions appropriately.
+public class MutexWaitOne2
+{
+ #region Public Constants
+ public const int c_DEFAULT_SLEEP_TIME = 1000; // 1 second
+ public const int c_LONG_SLEEP_TIME = 5000; // 5 second
+ #endregion
+
+ #region Private Fields
+ private Mutex m_Mutex = null;
+ #endregion
+
+ #region Public Methods
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+ retVal = PosTest2() && retVal;
+ retVal = PosTest3() && retVal;
+ retVal = PosTest4() && retVal;
+ retVal = PosTest5() && retVal;
+ retVal = PosTest6() && retVal;
+ retVal = PosTest7() && retVal;
+
+ TestLibrary.TestFramework.LogInformation("[Negative]");
+ retVal = NegTest1() && retVal;
+ retVal = NegTest2() && retVal;
+ retVal = NegTest3() && retVal;
+
+ return retVal;
+ }
+
+ #region Positive Test Cases
+ public bool PosTest1()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Wait Infinite");
+
+ try
+ {
+ do
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(SleepLongTime));
+ thread.Start();
+
+ if (m_Mutex.WaitOne(Timeout.Infinite) != true)
+ {
+ TestLibrary.TestFramework.LogError("001", "Can not wait Infinite");
+ retVal = false;
+
+ break;
+ }
+
+ m_Mutex.ReleaseMutex();
+
+ } while (false); // do
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Wait for the thread to terminate
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ m_Mutex.Dispose();
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest2()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest2: Wait some finite time");
+
+ try
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(SignalMutex));
+ thread.Start();
+
+ m_Mutex.WaitOne(2 * c_DEFAULT_SLEEP_TIME);
+
+ m_Mutex.ReleaseMutex();
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Wait for the thread to terminate
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ m_Mutex.Dispose();
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest3()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest3: Wait some finite time will quit for timeout");
+
+ try
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(SignalMutex));
+ thread.Start();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
+ if (false != m_Mutex.WaitOne(c_DEFAULT_SLEEP_TIME / 10))
+ {
+ m_Mutex.ReleaseMutex();
+ TestLibrary.TestFramework.LogError("004", "WaitOne returns true when wait time out");
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Wait for the thread to terminate
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ m_Mutex.Dispose();
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest4()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest4: Wait some finite time will quit for timeout when another thread is in nondefault managed context");
+
+ try
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(CallContextBoundObjectMethod));
+ thread.Start();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
+ if (false != m_Mutex.WaitOne(c_DEFAULT_SLEEP_TIME))
+ {
+ m_Mutex.ReleaseMutex();
+ TestLibrary.TestFramework.LogError("006", "WaitOne returns true when wait some finite time will quit for timeout when another thread is in nondefault managed context");
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("007", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Wait for the thread to terminate
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ m_Mutex.Dispose();
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest5()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest5: Wait some finite time will quit for timeout when another thread is in nondefault managed context");
+
+ try
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(CallContextBoundObjectMethod));
+ thread.Start();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
+ if (false != m_Mutex.WaitOne(c_DEFAULT_SLEEP_TIME))
+ {
+ m_Mutex.ReleaseMutex();
+ TestLibrary.TestFramework.LogError("008", "WaitOne returns true when wait some finite time will quit for timeout when another thread is in nondefault managed context");
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("009", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Wait for the thread to terminate
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ m_Mutex.Dispose();
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest6()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest6: Wait infinite time when another thread is in nondefault managed context");
+
+ try
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(CallContextBoundObjectMethod));
+ thread.Start();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
+ if (true != m_Mutex.WaitOne(Timeout.Infinite))
+ {
+ m_Mutex.ReleaseMutex();
+ TestLibrary.TestFramework.LogError("010", "WaitOne returns false when wait infinite time when another thread is in nondefault managed context");
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("011", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Wait for the thread to terminate
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ m_Mutex.Dispose();
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest7()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest7: Wait infinite time when another thread is in nondefault managed context");
+
+ try
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(CallContextBoundObjectMethod));
+ thread.Start();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
+ if (true != m_Mutex.WaitOne(Timeout.Infinite))
+ {
+ m_Mutex.ReleaseMutex();
+ TestLibrary.TestFramework.LogError("012", "WaitOne returns false when wait infinite time when another thread is in nondefault managed context");
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("013", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Wait for the thread to terminate
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ m_Mutex.Dispose();
+ }
+ }
+
+ return retVal;
+ }
+ #endregion
+
+ #region Negative Test Cases
+ public bool NegTest1()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("NegTest1: AbandonedMutexException should be thrown if a thread exited without releasing a mutex");
+
+ try
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(NeverReleaseMutex));
+ thread.Start();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
+ m_Mutex.WaitOne(Timeout.Infinite);
+
+ // AbandonedMutexException is not thrown on Windows 98 or Windows ME
+ //if (Environment.OSVersion.Platform == PlatformID.Win32NT)
+ //{
+ TestLibrary.TestFramework.LogError("101", "AbandonedMutexException is not thrown if a thread exited without releasing a mutex");
+ retVal = false;
+ //}
+ }
+ catch (AbandonedMutexException)
+ {
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ m_Mutex.Dispose();
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool NegTest2()
+ {
+ bool retVal = true;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("NegTest2: ObjectDisposedException should be thrown if current instance has already been disposed");
+
+ try
+ {
+ m_Mutex = new Mutex();
+
+ thread = new Thread(new ThreadStart(DisposeMutex));
+ thread.Start();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ m_Mutex.WaitOne(Timeout.Infinite);
+
+ TestLibrary.TestFramework.LogError("103", "ObjectDisposedException is not thrown if current instance has already been disposed");
+ retVal = false;
+ }
+ catch (ObjectDisposedException)
+ {
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ if (null != thread)
+ {
+ thread.Join();
+ }
+
+ if (null != m_Mutex)
+ {
+ ((IDisposable)m_Mutex).Dispose();
+ }
+ }
+
+ return retVal;
+ }
+
+ public bool NegTest3()
+ {
+ bool retVal = true;
+ int testInt = 0;
+
+ TestLibrary.TestFramework.BeginScenario("NegTest3: Check ArgumentOutOfRangeException will be thrown if millisecondsTimeout is a negative number other than -1");
+
+ try
+ {
+ testInt = TestLibrary.Generator.GetInt32();
+
+ if (testInt > 0)
+ {
+ testInt = 0 - testInt;
+ }
+
+ if (testInt == -1)
+ {
+ testInt--;
+ }
+
+ m_Mutex = new Mutex();
+ m_Mutex.WaitOne(testInt);
+
+ TestLibrary.TestFramework.LogError("105", "ArgumentOutOfRangeException is not thrown if millisecondsTimeout is a negative number other than -1");
+ TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] testInt = " + testInt);
+ retVal = false;
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("106", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] testInt = " + testInt);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ if (null != m_Mutex)
+ {
+ m_Mutex.Dispose();
+ }
+ }
+
+ return retVal;
+ }
+ #endregion
+ #endregion
+
+ public static int Main()
+ {
+ MutexWaitOne2 test = new MutexWaitOne2();
+
+ TestLibrary.TestFramework.BeginTestCase("MutexWaitOne2");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ #region Private Methods
+ private void SleepLongTime()
+ {
+ m_Mutex.WaitOne();
+ Thread.Sleep(c_LONG_SLEEP_TIME);
+ m_Mutex.ReleaseMutex();
+ }
+
+ private void SignalMutex()
+ {
+ m_Mutex.WaitOne();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ m_Mutex.ReleaseMutex();
+ }
+
+ private void NeverReleaseMutex()
+ {
+ m_Mutex.WaitOne();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ }
+
+ private void DisposeMutex()
+ {
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ ((IDisposable)m_Mutex).Dispose();
+ }
+
+ private void CallContextBoundObjectMethod()
+ {
+ m_Mutex.WaitOne();
+ TestContextBoundObject obj = new TestContextBoundObject();
+ obj.TestMethod();
+ m_Mutex.ReleaseMutex();
+ }
+ #endregion
+}
diff --git a/tests/src/baseservices/threading/mutex/misc/waitone2.csproj b/tests/src/baseservices/threading/mutex/misc/waitone2.csproj
new file mode 100644
index 0000000000..d0c3e767e3
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/misc/waitone2.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOne2.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/app.config b/tests/src/baseservices/threading/mutex/openexisting/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg1.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg1.cs
new file mode 100644
index 0000000000..d14cff6915
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg1.cs
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexNeg
+{
+ public static int Main()
+ {
+ OpenMutexNeg omn = new OpenMutexNeg();
+ return omn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Mutex mut;
+ try
+ {
+ mut = Mutex.OpenExisting(Common.GetUniqueName());
+ }
+ catch (WaitHandleCannotBeOpenedException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg1.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg1.csproj
new file mode 100644
index 0000000000..59af4a0d37
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg1.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexNeg1.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg2.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg2.cs
new file mode 100644
index 0000000000..5bc9a5a4cd
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg2.cs
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexNeg
+{
+ public static int Main()
+ {
+ OpenMutexNeg omn = new OpenMutexNeg();
+ return omn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Mutex mut;
+ try
+ {
+ mut = Mutex.OpenExisting("");
+ }
+ catch (ArgumentException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg2.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg2.csproj
new file mode 100644
index 0000000000..981ef3853b
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg2.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexNeg2.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg3.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg3.cs
new file mode 100644
index 0000000000..734e0c4309
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg3.cs
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexNeg
+{
+ public static int Main()
+ {
+ OpenMutexNeg omn = new OpenMutexNeg();
+ return omn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Mutex mut;
+ try
+ {
+ mut = Mutex.OpenExisting(null);
+ }
+ catch (ArgumentNullException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg3.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg3.csproj
new file mode 100644
index 0000000000..1073aefadf
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg3.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexNeg3.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg4.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg4.cs
new file mode 100644
index 0000000000..2511dcf996
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg4.cs
@@ -0,0 +1,39 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexNeg
+{
+ public static int Main()
+ {
+ OpenMutexNeg omn = new OpenMutexNeg();
+ return omn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Mutex mut;
+ try
+ {
+ String myMut = null;
+ mut = Mutex.OpenExisting(myMut);
+ }
+ catch (ArgumentNullException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg4.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg4.csproj
new file mode 100644
index 0000000000..d137d0e65d
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg4.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexNeg4.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg5.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg5.cs
new file mode 100644
index 0000000000..0cd7db0cb1
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg5.cs
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexNeg
+{
+ public static int Main()
+ {
+ OpenMutexNeg omn = new OpenMutexNeg();
+ return omn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ string sName = Common.GetUniqueName();
+ // open a closed mutex
+ try
+ {
+ using (Mutex mut1 = new Mutex(false, sName)) {}
+ Mutex mut2 = Mutex.OpenExisting(sName);
+ }
+ catch (WaitHandleCannotBeOpenedException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg5.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg5.csproj
new file mode 100644
index 0000000000..b314d17985
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg5.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexNeg5.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg6.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg6.cs
new file mode 100644
index 0000000000..9979366f42
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg6.cs
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexNeg
+{
+ public static int Main()
+ {
+ OpenMutexNeg omn = new OpenMutexNeg();
+ return omn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ string sName = Common.GetUniqueName();
+ // open a Mutex with the same name as a Semaphore
+ using (Semaphore sem = new Semaphore(10, 10, sName))
+ {
+ try
+ {
+ Mutex mut = Mutex.OpenExisting(sName);
+ }
+ catch(WaitHandleCannotBeOpenedException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught exception where WaitHandleCannotBeOpenedException was expected: " +
+ e.ToString());
+ }
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg6.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg6.csproj
new file mode 100644
index 0000000000..7defe8393a
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg6.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexNeg6.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg7.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg7.cs
new file mode 100644
index 0000000000..c4846141e8
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg7.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexNeg
+{
+ public ManualResetEvent mre;
+ public Mutex mut;
+
+ public OpenMutexNeg()
+ {
+ mre = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ OpenMutexNeg omn = new OpenMutexNeg();
+ return omn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ string sName = Common.GetUniqueName();
+ // open a Mutex that has been abandoned
+ mut = new Mutex(false, sName);
+ Thread th = new Thread(new ParameterizedThreadStart(AbandonMutex));
+ th.Start(mut);
+ mre.WaitOne();
+ try
+ {
+ Mutex mut1 = Mutex.OpenExisting(sName);
+ mut1.WaitOne();
+ }
+ catch (AbandonedMutexException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutex(Object o)
+ {
+ ((Mutex)o).WaitOne();
+ mre.Set();
+ Thread.Sleep(1000);
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg7.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg7.csproj
new file mode 100644
index 0000000000..5518c816cf
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg7.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexNeg7.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg8.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg8.cs
new file mode 100644
index 0000000000..ff47944833
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg8.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexNeg
+{
+ public Mutex mut;
+
+ public static int Main()
+ {
+ OpenMutexNeg omn = new OpenMutexNeg();
+ return omn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ // open a Mutex, not case specific
+ mut = new Mutex(false, "This is a Mutex that is Case Specific");
+ try
+ {
+ Mutex mut1 = Mutex.OpenExisting("This is a Mutex that is Case specific");
+ }
+ catch (WaitHandleCannotBeOpenedException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexneg8.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg8.csproj
new file mode 100644
index 0000000000..653c28a5bb
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexneg8.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexNeg8.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexpos1.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos1.cs
new file mode 100644
index 0000000000..93f53a82bc
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos1.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexPos
+{
+ Mutex mut;
+ ManualResetEvent mre;
+
+ public OpenMutexPos()
+ {
+ mre = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ OpenMutexPos omp = new OpenMutexPos();
+ return omp.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ string sName = Common.GetUniqueName();
+ // Basic test, not owned
+ using(mut = new Mutex(false, sName))
+ {
+ Thread t = new Thread(new ThreadStart(OwnMutex));
+ t.Start();
+ mre.WaitOne();
+ try
+ {
+ Mutex mut1 = Mutex.OpenExisting(sName);
+ mut1.WaitOne();
+ mut1.ReleaseMutex();
+ iRet = 100;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ ex.ToString());
+ }
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void OwnMutex()
+ {
+ mut.WaitOne();
+ mre.Set();
+ Thread.Sleep(3000);
+ mut.ReleaseMutex();
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexpos1.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos1.csproj
new file mode 100644
index 0000000000..339dfbc7e2
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos1.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexPos1.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexpos2.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos2.cs
new file mode 100644
index 0000000000..9581bdb517
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos2.cs
@@ -0,0 +1,46 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexPos
+{
+ Mutex mut;
+ ManualResetEvent mre;
+
+ public OpenMutexPos()
+ {
+ mre = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ OpenMutexPos omp = new OpenMutexPos();
+ return omp.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ string sName = Common.GetUniqueName();
+ // Basic test, owned
+ using (mut = new Mutex(true, sName))
+ {
+ try
+ {
+ Mutex mut1 = Mutex.OpenExisting(sName);
+ iRet = 100;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ ex.ToString());
+ }
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexpos2.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos2.csproj
new file mode 100644
index 0000000000..372cb947aa
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos2.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexPos2.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexpos3.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos3.cs
new file mode 100644
index 0000000000..01abc0de33
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos3.cs
@@ -0,0 +1,48 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenMutexPos
+{
+ Mutex mut;
+
+ public static int Main()
+ {
+ OpenMutexPos omp = new OpenMutexPos();
+ return omp.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ string sName = Common.GetUniqueName();
+ // Open an abandoned mutex
+ using (mut = new Mutex(false, sName))
+ {
+ Thread t = new Thread(new ThreadStart(AbandonMutex));
+ t.Start();
+ t.Join();
+ try
+ {
+ Mutex mut1 = Mutex.OpenExisting(sName);
+ iRet = 100;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ ex.ToString());
+ }
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutex()
+ {
+ mut.WaitOne();
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexpos3.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos3.csproj
new file mode 100644
index 0000000000..d5583cc3a0
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos3.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexPos3.cs" />
+ <Compile Include="..\OpenMutexCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexpos4.cs b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos4.cs
new file mode 100644
index 0000000000..c46dc61b1b
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos4.cs
@@ -0,0 +1,85 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+/// <summary>
+/// Verifies if we CreateMutex adn then OpenMutex we don't have ownership of the mutex.
+/// </summary>
+public class Test
+{
+ const string mutexName = "MySharedMutex";
+ static ManualResetEvent manualEvent = new ManualResetEvent(false);
+ static ManualResetEvent exitEvent = new ManualResetEvent(false);
+ int success = 100;
+
+
+ public void CreateMutexThread()
+ {
+ Console.WriteLine("Inside thread which creates a mutex");
+
+ Mutex mutex = new Mutex(true, mutexName);
+
+
+ Console.WriteLine("Mutex created");
+
+ manualEvent.Set();
+ mutex.ReleaseMutex();
+
+ exitEvent.WaitOne();
+ }
+
+ public void ReuseMutexThread()
+ {
+ Console.WriteLine("Waiting to reuse mutex");
+ manualEvent.WaitOne();
+ bool exists;
+
+ Mutex mutex = new Mutex(true, mutexName, out exists);
+
+ if (exists)
+ {
+ Console.WriteLine("Error, created new mutex!");
+ success = 97;
+ }
+ else
+ {
+ mutex.WaitOne();
+ }
+
+
+ try
+ {
+ Console.WriteLine("Mutex reused {0}", exists);
+ mutex.ReleaseMutex();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Unexpected exception: {0}", e);
+ success = 98;
+ }
+
+ exitEvent.Set();
+ }
+
+ int RunTest()
+ {
+ Thread t1 = new Thread(new ThreadStart(CreateMutexThread));
+ Thread t2 = new Thread(new ThreadStart(ReuseMutexThread));
+ t1.Start();
+ t2.Start();
+ t1.Join();
+ t2.Join();
+
+ if (success == 100) Console.WriteLine("Test passed"); else Console.WriteLine("Test failed");
+ return (success);
+ }
+
+ public static int Main()
+ {
+ return (new Test().RunTest());
+ }
+}
+
diff --git a/tests/src/baseservices/threading/mutex/openexisting/openmutexpos4.csproj b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos4.csproj
new file mode 100644
index 0000000000..7769ad7090
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/openmutexpos4.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OpenMutexPos4.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openexisting/project.json b/tests/src/baseservices/threading/mutex/openexisting/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openexisting/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/mutex/openmutexcommon.cs b/tests/src/baseservices/threading/mutex/openmutexcommon.cs
new file mode 100644
index 0000000000..fce7fc3044
--- /dev/null
+++ b/tests/src/baseservices/threading/mutex/openmutexcommon.cs
@@ -0,0 +1,32 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class Common
+{
+ public static string GenerateUnicodeString(int iNumChars)
+ {
+ Random rand = new Random();
+ string semName = string.Empty;
+ string semNameNum = string.Empty;
+ for (int i = 0; i < iNumChars; i++)
+ {
+ char c = (char)rand.Next(Char.MinValue, Char.MaxValue);
+ semNameNum += ((int)c).ToString() + ";";
+ semName += (char)rand.Next(Char.MinValue, Char.MaxValue);
+ }
+ // write to output
+ Console.WriteLine("Unicode string: " + semNameNum);
+ return semName;
+ }
+
+ public static string GetUniqueName()
+ {
+ string sName = Guid.NewGuid().ToString();
+ Console.WriteLine("Name created: " + sName);
+ return sName;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/paramthreadstart/threadstartarray.cs b/tests/src/baseservices/threading/paramthreadstart/threadstartarray.cs
new file mode 100644
index 0000000000..30f9074b4f
--- /dev/null
+++ b/tests/src/baseservices/threading/paramthreadstart/threadstartarray.cs
@@ -0,0 +1,58 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class ThreadStartArray
+{
+ Mutex[] m;
+ AutoResetEvent are = new AutoResetEvent(false);
+
+ public static int Main()
+ {
+ // Abandon this mutex
+ Mutex[] mArr = new Mutex[64];
+ for(int i=0;i<mArr.Length;i++)
+ mArr[i] = new Mutex(false);
+
+ ThreadStartArray tsa = new ThreadStartArray();
+ return tsa.Run(mArr);
+ }
+
+ private int Run(Mutex[] mPass)
+ {
+ bool bRet = false;
+ Thread t = new Thread(new ParameterizedThreadStart(ThreadWorker));
+ t.Start(mPass);
+ are.WaitOne();
+
+ // Check to make sure the array is abandoned
+ try
+ {
+ WaitHandle.WaitAny(m, 10000);
+ }
+ catch(AbandonedMutexException)
+ {
+ bRet = true;
+ }
+ catch(Exception ex)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + ex.ToString());
+ }
+
+ Console.WriteLine(bRet ? "Test Passed" : "Test Failed");
+ return (bRet ? 100 : -1);
+ }
+
+ private void ThreadWorker(Object o)
+ {
+ for(int i = 0;i<((Mutex[])o).Length;i++)
+ ((Mutex[])o)[i].WaitOne();
+
+ m = (Mutex[])o;
+ are.Set();
+ Thread.Sleep(1000);
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/paramthreadstart/threadstartarray.csproj b/tests/src/baseservices/threading/paramthreadstart/threadstartarray.csproj
new file mode 100644
index 0000000000..f3efd97f07
--- /dev/null
+++ b/tests/src/baseservices/threading/paramthreadstart/threadstartarray.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ThreadStartArray.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/paramthreadstart/threadstartclass.cs b/tests/src/baseservices/threading/paramthreadstart/threadstartclass.cs
new file mode 100644
index 0000000000..e3667b04b2
--- /dev/null
+++ b/tests/src/baseservices/threading/paramthreadstart/threadstartclass.cs
@@ -0,0 +1,52 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Diagnostics;
+
+class ThreadStartClass
+{
+ Object oSaved = null;
+
+ public static int Main(string[] args)
+ {
+ ThreadStartClass tsc = new ThreadStartClass();
+ return tsc.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = 100;
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ Thread.Sleep(1000);
+ sw.Stop();
+
+ Thread t = new Thread(new ParameterizedThreadStart(ThreadWorker));
+ t.Start(sw);
+ t.Join();
+
+ if (sw.ElapsedMilliseconds != ((Stopwatch)oSaved).ElapsedMilliseconds)
+ {
+ Console.WriteLine("Expected ((Stopwatch)oSaved).ElapsedMilliseconds = sw.ElapsedMilliseconds=" + sw.ElapsedMilliseconds.ToString());
+ Console.WriteLine("Actual oSaved.ElapsedMilliseconds=" + ((Stopwatch)oSaved).ElapsedMilliseconds.ToString());
+ iRet = 98;
+ }
+ Console.WriteLine("Expected ((Stopwatch)oSaved).ElapsedMilliseconds to be 1000, but found " + ((Stopwatch)oSaved).ElapsedMilliseconds);
+ if (((Stopwatch)oSaved).ElapsedMilliseconds < 950)
+ {
+ Console.WriteLine("Expected ((Stopwatch)oSaved).ElapsedMilliseconds to be 1000, but found " + ((Stopwatch)oSaved).ElapsedMilliseconds);
+ iRet = 97;
+ }
+
+ Console.WriteLine(iRet==100 ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void ThreadWorker(Object o)
+ {
+ oSaved = o;
+ }
+}
diff --git a/tests/src/baseservices/threading/paramthreadstart/threadstartclass.csproj b/tests/src/baseservices/threading/paramthreadstart/threadstartclass.csproj
new file mode 100644
index 0000000000..36f444594a
--- /dev/null
+++ b/tests/src/baseservices/threading/paramthreadstart/threadstartclass.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ThreadStartClass.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/paramthreadstart/threadstartstruct.cs b/tests/src/baseservices/threading/paramthreadstart/threadstartstruct.cs
new file mode 100644
index 0000000000..f6e5e54725
--- /dev/null
+++ b/tests/src/baseservices/threading/paramthreadstart/threadstartstruct.cs
@@ -0,0 +1,67 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class ThreadStartStruct
+{
+ int iRet = -1;
+
+ public struct MyStruct
+ {
+ public int myInt;
+ public string myStr;
+ public long myLong;
+ public double myDouble;
+ public Mutex myMutex;
+ }
+
+ public static int Main()
+ {
+ ThreadStartStruct tss = new ThreadStartStruct();
+ return tss.Run();
+ }
+
+ private int Run()
+ {
+ MyStruct m = new MyStruct();
+ m.myInt = Int32.MinValue;
+ m.myStr = "This is the string";
+ m.myLong = Int64.MaxValue;
+ m.myDouble = Double.MinValue;
+ m.myMutex = new Mutex(true);
+
+ Thread t = new Thread(new ParameterizedThreadStart(ThreadWorker));
+ t.Start(m);
+ // Test to see if it passing an owned mutex
+ Thread.Sleep(1000);
+ m.myMutex.ReleaseMutex();
+ t.Join();
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return (100 == iRet ? 100 : -1);
+ }
+
+ private void ThreadWorker(Object o)
+ {
+ if(Int32.MinValue == ((MyStruct)o).myInt &&
+ "This is the string" == ((MyStruct)o).myStr &&
+ Int64.MaxValue == ((MyStruct)o).myLong &&
+ Double.MinValue == ((MyStruct)o).myDouble)
+ {
+ try
+ {
+ ((MyStruct)o).myMutex.WaitOne();
+ ((MyStruct)o).myMutex.ReleaseMutex();
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/paramthreadstart/threadstartstruct.csproj b/tests/src/baseservices/threading/paramthreadstart/threadstartstruct.csproj
new file mode 100644
index 0000000000..a88b8fed2c
--- /dev/null
+++ b/tests/src/baseservices/threading/paramthreadstart/threadstartstruct.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ThreadStartStruct.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/readerwriterlockslim/project.json b/tests/src/baseservices/threading/readerwriterlockslim/project.json
deleted file mode 100644
index a2e84dc340..0000000000
--- a/tests/src/baseservices/threading/readerwriterlockslim/project.json
+++ /dev/null
@@ -1,35 +0,0 @@
-{
- "dependencies": {
- "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
- "System.Collections": "4.0.10",
- "System.Collections.NonGeneric": "4.0.1-rc2-23816",
- "System.Collections.Specialized": "4.0.1-rc2-23816",
- "System.ComponentModel": "4.0.1-rc2-23816",
- "System.Console": "4.0.0-rc2-23816",
- "System.Diagnostics.Process": "4.1.0-rc2-23816",
- "System.Globalization": "4.0.10",
- "System.Globalization.Calendars": "4.0.0",
- "System.IO": "4.0.10",
- "System.IO.FileSystem": "4.0.0",
- "System.IO.FileSystem.Primitives": "4.0.0",
- "System.Linq": "4.0.1-rc2-23816",
- "System.Linq.Queryable": "4.0.1-rc2-23816",
- "System.Reflection": "4.0.10",
- "System.Reflection.Primitives": "4.0.0",
- "System.Runtime": "4.1.0-rc2-23816",
- "System.Runtime.Extensions": "4.0.10",
- "System.Runtime.Handles": "4.0.0",
- "System.Runtime.InteropServices": "4.1.0-rc2-23816",
- "System.Runtime.Loader": "4.0.0-rc2-23816",
- "System.Text.Encoding": "4.0.10",
- "System.Threading": "4.0.10",
- "System.Threading.Thread": "4.0.0-rc2-23816",
- "System.Xml.ReaderWriter": "4.0.11-rc2-23816",
- "System.Xml.XDocument": "4.0.11-rc2-23816",
- "System.Xml.XmlDocument": "4.0.1-rc2-23816",
- "System.Xml.XmlSerializer": "4.0.11-rc2-23816"
- },
- "frameworks": {
- "dnxcore50": {}
- }
-}
diff --git a/tests/src/baseservices/threading/readerwriterlockslim/singlereleasewriteddbug71632.cs b/tests/src/baseservices/threading/readerwriterlockslim/singlereleasewriteddbug71632.cs
deleted file mode 100644
index 842e392858..0000000000
--- a/tests/src/baseservices/threading/readerwriterlockslim/singlereleasewriteddbug71632.cs
+++ /dev/null
@@ -1,159 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-using System;
-using System.Threading;
-
-class C
-{
- private ReaderWriterLockSlim rwls;
- private ManualResetEvent mre;
- private ManualResetEvent mre1;
- private int threadCount = 100;
- private int oneThreadAccess;
-
- static int Main()
- {
- return (new C()).RunTest();
- }
-
- public int RunTest()
- {
- int retCode = -10;
- rwls = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
- threadCount = 0;
- oneThreadAccess = 0;
-
- retCode = DoTesting();
-
- return retCode;
- }
-
- private int DoTesting()
- {
- mre = new ManualResetEvent(false);
- mre1 = new ManualResetEvent(false);
- Thread[] threadArray = new Thread[5];
- threadArray[0] = new Thread(this.LockTaker);
- threadArray[0].Start();
- mre1.WaitOne();
- for (int i = 1; i < threadArray.Length; i++)
- {
- threadArray[i] = new Thread(this.LockCompetitor);
- threadArray[i].Start();
- }
-
- for (int i = 0; i < threadArray.Length; i++)
- {
- threadArray[i].Join();
- }
-
- mre = new ManualResetEvent(false);
- mre1 = new ManualResetEvent(false);
- threadArray[0] = new Thread(this.LockTakerWrite);
- threadArray[0].Start();
- mre1.WaitOne();
- for (int i = 1; i < threadArray.Length; i++)
- {
- threadArray[i] = new Thread(this.LockCompetitorWrite);
- threadArray[i].Start();
- }
-
- for (int i = 0; i < threadArray.Length; i++)
- {
- threadArray[i].Join();
- }
- if (threadCount == 8)
- return 100;
- else
- return threadCount;
- }
-
- void LockTaker()
- {
- rwls.EnterUpgradeableReadLock();
- Interlocked.Increment(ref oneThreadAccess);
- mre1.Set();
- mre.WaitOne();
- Thread.Sleep(1000);
- if (oneThreadAccess != 1)
- {
- Console.WriteLine("Expected original UpgradeLock to have the lock, but a second thread appears to have modified oneThreadAccess");
- threadCount = 50;
- }
- Interlocked.Decrement(ref oneThreadAccess);
- if (oneThreadAccess != 0)
- {
- Console.WriteLine("Expected original UpgradeLock to have the lock, but a second thread appears to have modified oneThreadAccess");
- threadCount = 60;
- }
- rwls.ExitUpgradeableReadLock();
- }
-
- void LockCompetitor()
- {
- Interlocked.Increment(ref threadCount);
- if (threadCount == 4)
- mre.Set();
- rwls.EnterUpgradeableReadLock();
- Interlocked.Increment(ref oneThreadAccess);
- Thread.Sleep(2000);
- if (oneThreadAccess != 1)
- {
- Console.WriteLine("Expected original UpgradeLock to have the lock, but a second thread appears to have modified oneThreadAccess");
- threadCount = 70;
- }
- Interlocked.Decrement(ref oneThreadAccess);
- Thread.Sleep(3000);
- if (oneThreadAccess != 0)
- {
- Console.WriteLine("Expected original UpgradeLock to have the lock, but a second thread appears to have modified oneThreadAccess");
- threadCount = 80;
- }
- rwls.ExitUpgradeableReadLock();
- }
-
- void LockTakerWrite()
- {
- rwls.EnterWriteLock();
- Interlocked.Increment(ref oneThreadAccess);
- mre1.Set();
- mre.WaitOne();
- Thread.Sleep(1000);
- if (oneThreadAccess != 1)
- {
- Console.WriteLine("Expected original WriteLock to have the lock, but a second thread appears to have modified oneThreadAccess");
- threadCount = 50;
- }
- Interlocked.Decrement(ref oneThreadAccess);
- if (oneThreadAccess != 0)
- {
- Console.WriteLine("Expected original WriteLock to have the lock, but a second thread appears to have modified oneThreadAccess");
- threadCount = 60;
- }
- rwls.ExitWriteLock();
- }
-
- void LockCompetitorWrite()
- {
- Interlocked.Increment(ref threadCount);
- if (threadCount == 8)
- mre.Set();
- rwls.EnterWriteLock();
- Interlocked.Increment(ref oneThreadAccess);
- Thread.Sleep(2000);
- if (oneThreadAccess != 1)
- {
- Console.WriteLine("Expected original WriteLock to have the lock, but a second thread appears to have modified oneThreadAccess");
- threadCount = 70;
- }
- Interlocked.Decrement(ref oneThreadAccess);
- Thread.Sleep(3000);
- if (oneThreadAccess != 0)
- {
- Console.WriteLine("Expected original WriteLock to have the lock, but a second thread appears to have modified oneThreadAccess");
- threadCount = 80;
- }
- rwls.ExitWriteLock();
- }
-} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/readerwriterlockslim/tryenterfailureddbugs124485.cs b/tests/src/baseservices/threading/readerwriterlockslim/tryenterfailureddbugs124485.cs
deleted file mode 100644
index ad5480c4a3..0000000000
--- a/tests/src/baseservices/threading/readerwriterlockslim/tryenterfailureddbugs124485.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-using System;
-using System.Threading;
-
-class Program
-{
- private ReaderWriterLockSlim rwls = new ReaderWriterLockSlim();
-
- public int RunTest()
- {
- bool lockTaken = false;
- int retCode = 25;
- try
- {
- lockTaken = false;
- Console.WriteLine("Attempting rwls.TryEnterUpgradeableReadLock(-2647); on unowned lock");
- lockTaken = rwls.TryEnterUpgradeableReadLock(-2647);
- retCode = -100;
- Console.WriteLine("Expected exception but aquired lock. Failing test.");
- }
- catch (ArgumentException ae)
- {
- retCode = retCode + 25;
- Console.WriteLine("As expected: Caught ArgumentException\n{0}", ae.Message);
- }
- finally
- {
- if (lockTaken)
- {
- rwls.ExitUpgradeableReadLock();
- }
- }
-
- try
- {
- lockTaken = false;
- Console.WriteLine();
- Console.WriteLine("Attempting rwls.TryEnterReadLock(-2647); on unowned lock");
- lockTaken = rwls.TryEnterReadLock(-2647);
- retCode = -110;
- Console.WriteLine("Expected exception but aquired lock. Failing test.");
- }
- catch (ArgumentException ae)
- {
- retCode = retCode + 25;
- Console.WriteLine("As expected: Caught ArgumentException\n{0}", ae.Message);
- }
- finally
- {
- if (lockTaken)
- {
- rwls.ExitReadLock();
- }
- }
-
- try
- {
- lockTaken = false;
- Console.WriteLine();
- Console.WriteLine("Attempting rwls.TryEnterWriteLock(-2647); on unowned lock");
- lockTaken = rwls.TryEnterWriteLock(-2647);
- retCode = -120;
- Console.WriteLine("Expected exception but aquired lock. Failing test.");
- }
- catch (ArgumentException ae)
- {
- retCode = retCode + 25;
- Console.WriteLine("As expected: Caught ArgumentException\n{0}", ae.Message);
- }
- finally
- {
- if (lockTaken)
- {
- rwls.ExitWriteLock();
- }
- }
-
- return retCode;
- }
-
- static int Main()
- {
- return (new Program()).RunTest();
- }
-} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/readerwriterlockslim/upgrader.cs b/tests/src/baseservices/threading/readerwriterlockslim/upgrader.cs
deleted file mode 100644
index 05543089d2..0000000000
--- a/tests/src/baseservices/threading/readerwriterlockslim/upgrader.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-using System;
-using System.Threading;
-
-class Upgrader
-{
- private static ReaderWriterLockSlim rwls = new ReaderWriterLockSlim();
- private const int readerCount = 10;
- private static CountdownEvent ev = new CountdownEvent(readerCount);
-
- /// <summary>
- /// This is the thread body that will try to enter read/write/upgrade
- /// lock.
- /// </summary>
- /// <param name="threadIndex"></param>
- /// <param name="lockAction">0: try enter read lock; 1: try enter write lock; other value: try enter upgrade lock</param>
- public static void ThreadMethod(object parameters)
- {
- object[] parameterArray = (object[]) parameters;
- int threadIndex = (int)parameterArray[0];
- int lockAction = (int)parameterArray[1];
-
- if (lockAction == 0)
- Upgrader.rwls.EnterReadLock();
- else if (lockAction == 1)
- Upgrader.rwls.EnterWriteLock();
- else
- Upgrader.rwls.EnterUpgradeableReadLock();
-
- Upgrader.ev.Signal();
- Console.WriteLine(" @Thread {0} Signal ", threadIndex);
- Thread.CurrentThread.Join();
- }
-
- public static int RunTest()
- {
- int retCode = 0;
-
- try
- {
- Upgrader.rwls.EnterUpgradeableReadLock();
- Console.WriteLine(" Main thread EnterUpgradeableReadLock !");
-
- for (int i = 0; i < readerCount; i++)
- {
- Thread t = new Thread(new ParameterizedThreadStart(Upgrader.ThreadMethod));
- object[] parameters = new object[] { i, 0 };
- // The thread MUST be set to background thread otherwise it will be dead forever
- t.IsBackground = true;
- t.Start(parameters);
- Console.WriteLine(" @Thread {0} start ", i);
- }
-
- ev.Wait();
- Console.WriteLine(" ev.wait ");
- if (rwls.TryEnterWriteLock(5 * 1000))
- {
- Console.WriteLine(" Wrong: @Main thread enter Write Lock! ");
- retCode = 90;
- }
- else
- {
- Console.WriteLine(" @Main thread cannot enter Write Lock! ");
- retCode = 100;
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("Wrong: Unexpected exception happened!");
- Console.WriteLine(e.ToString());
- retCode = 80;
- }
- return retCode;
- }
-
- static int Main()
- {
- int retCode = Upgrader.RunTest();
- if (retCode == 100)
- Console.WriteLine(" Test Passed! ");
- else
- Console.WriteLine(" Test Failed! ");
- return retCode;
- }
-} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/135972/app.config b/tests/src/baseservices/threading/regressions/135972/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/135972/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/regressions/135972/oswaitinlock.cs b/tests/src/baseservices/threading/regressions/135972/oswaitinlock.cs
new file mode 100644
index 0000000000..ae9b4dcea0
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/135972/oswaitinlock.cs
@@ -0,0 +1,70 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class Bug
+{
+ public static int Main()
+ {
+ Console.WriteLine("Repro for Bug 135972");
+ TestCase bugCheck = new TestCase();
+ return bugCheck.Run();
+ }
+}
+
+public class TestCase
+{
+ private int ret;
+ private Object mylock;
+ private AutoResetEvent are;
+
+ public TestCase()
+ {
+ mylock = new Object();
+ are = new AutoResetEvent(false);
+ }
+
+ public int Run()
+ {
+ lock(mylock)
+ {
+ ret = 0;
+ Thread t;
+ t = new Thread(new ThreadStart(BlockThreadOnWait));
+ t.Start();
+ Thread.Sleep(3000);
+ Console.WriteLine("Signaling");
+ are.Set();
+ Thread.Sleep(1000);
+ Console.WriteLine("Main Waiting");
+ Thread.Sleep(1000);
+ Console.WriteLine("Aborting New Thread");
+ ThreadEx.Abort(t);
+ t.Join();
+ }
+ return ret;
+
+ }
+
+ public void BlockThreadOnWait()
+ {
+ try{
+ Console.WriteLine("New Thread Waiting");
+ are.WaitOne();
+ Console.WriteLine("New Thread Signaled");
+ lock(mylock){
+ //This line will never print since the lock is held by thread 1
+ //Need this here so the jit doesn't optimize this lock away
+ ret = -1;
+ Console.WriteLine("In The Lock Sleep");
+ }
+ }
+ catch(Exception)
+ {
+ Interlocked.CompareExchange(ref ret,100,0);
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/regressions/135972/oswaitinlock.csproj b/tests/src/baseservices/threading/regressions/135972/oswaitinlock.csproj
new file mode 100644
index 0000000000..6b5bbb2062
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/135972/oswaitinlock.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OSWaitInLock.cs" />
+ <Compile Include="..\threadex.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/135972/oswaitinsleep.cs b/tests/src/baseservices/threading/regressions/135972/oswaitinsleep.cs
new file mode 100644
index 0000000000..7ef2bfa4c4
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/135972/oswaitinsleep.cs
@@ -0,0 +1,68 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class Bug
+{
+ public static int Main()
+ {
+ Console.WriteLine("Repro for Bug 135972");
+ TestCase bugCheck = new TestCase();
+ return bugCheck.Run();
+ }
+}
+
+public class TestCase
+{
+ private int ret;
+ private Object mylock;
+ private AutoResetEvent are;
+
+ public TestCase()
+ {
+ mylock = new Object();
+ are = new AutoResetEvent(false);
+ }
+
+ public int Run()
+ {
+ lock(mylock)
+ {
+ ret = 0;
+ Thread t;
+ t = new Thread(new ThreadStart(BlockThreadOnWait));
+ t.Start();
+ Thread.Sleep(3000);
+ Console.WriteLine("Signaling");
+ are.Set();
+ Thread.Sleep(1000);
+ Console.WriteLine("Main Waiting");
+ Thread.Sleep(1000);
+ Console.WriteLine("Aborting New Thread");
+ ThreadEx.Abort(t);
+ t.Join();
+ }
+ return ret;
+
+ }
+
+ public void BlockThreadOnWait()
+ {
+ try{
+ Console.WriteLine("New Thread Waiting");
+ are.WaitOne();
+ Console.WriteLine("New Thread Signaled");
+ Thread.Sleep(Timeout.Infinite);
+ //Should never hit this line
+ ret = -1;
+ Console.WriteLine("In The Lock Sleep");
+ }
+ catch(Exception)
+ {
+ Interlocked.CompareExchange(ref ret,100,0);
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/regressions/135972/oswaitinsleep.csproj b/tests/src/baseservices/threading/regressions/135972/oswaitinsleep.csproj
new file mode 100644
index 0000000000..8d35d8bee5
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/135972/oswaitinsleep.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="OSWaitInSleep.cs" />
+ <Compile Include="..\threadex.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/135972/project.json b/tests/src/baseservices/threading/regressions/135972/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/135972/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/13662/13662-a.cs b/tests/src/baseservices/threading/regressions/13662/13662-a.cs
new file mode 100644
index 0000000000..c3f5d0fd87
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/13662/13662-a.cs
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+
+public class Test {
+
+ public static int Main(){
+
+ int rValue = 100;
+ Timer[] tArray = new Timer[1000];
+ int val = 0;
+ while(val < 10){
+ Interlocked.Increment(ref val);
+ Console.WriteLine("Loop {0}",val);
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ }
+ return rValue;
+ }
+
+ public static void TFunc(Object o)
+ {
+ Thread.Sleep(1);
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/13662/13662-a.csproj b/tests/src/baseservices/threading/regressions/13662/13662-a.csproj
new file mode 100644
index 0000000000..718296b7e0
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/13662/13662-a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="13662-a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/13662/13662-b.cs b/tests/src/baseservices/threading/regressions/13662/13662-b.cs
new file mode 100644
index 0000000000..1e7a4d9936
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/13662/13662-b.cs
@@ -0,0 +1,89 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+
+public class Test {
+
+ public static int Main(){
+
+ int rValue = 100;
+ Timer[] tArray = new Timer[1000];
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+
+ return rValue;
+ }
+
+ public static void TFunc(Object o)
+ {
+ Thread.Sleep(1);
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/13662/13662-b.csproj b/tests/src/baseservices/threading/regressions/13662/13662-b.csproj
new file mode 100644
index 0000000000..97a88c06c3
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/13662/13662-b.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="13662-b.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/13662/13662-simple.csproj b/tests/src/baseservices/threading/regressions/13662/13662-simple.csproj
new file mode 100644
index 0000000000..37324aa1c8
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/13662/13662-simple.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="simple.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/13662/app.config b/tests/src/baseservices/threading/regressions/13662/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/13662/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/regressions/13662/project.json b/tests/src/baseservices/threading/regressions/13662/project.json
new file mode 100644
index 0000000000..344736691a
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/13662/project.json
@@ -0,0 +1,34 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Threading.Timer": "4.0.0-rc3-23823",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/13662/simple.cs b/tests/src/baseservices/threading/regressions/13662/simple.cs
new file mode 100644
index 0000000000..230c63951f
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/13662/simple.cs
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+
+public class Test {
+
+ public static int Main(){
+
+ int rValue = 100;
+ Timer[] tArray = new Timer[100];
+ int val = 0;
+ while(val < 10){
+ Interlocked.Increment(ref val);
+ Console.WriteLine("Loop {0}",val);
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,1000000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ }
+ return rValue;
+ }
+
+ public static void TFunc(Object o)
+ {
+ Thread.Sleep(1);
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/269336/app.config b/tests/src/baseservices/threading/regressions/269336/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/269336/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/regressions/269336/objmonhelper.cs b/tests/src/baseservices/threading/regressions/269336/objmonhelper.cs
new file mode 100644
index 0000000000..60185dc496
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/269336/objmonhelper.cs
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class ObjMonHelper {
+ const string FailMsg = @"Monitor.Enter appears to have mistaken a hash code in an object header for
+a valid lock owned by the current thread.";
+
+ public static int Main() {
+ var ok = true;
+ var arr = new object[1024*1024];
+
+ // Call GetHashCode to populate the object header with its hash
+ for (var i = 0; i < arr.Length; i++) {
+ arr[i] = new object();
+ arr[i].GetHashCode();
+ }
+
+ // Attempt to lock and unlock each object. If the bug is present, the object will appear
+ // to be locked by the current thread and Monitor.Enter will incorrectly take a fast path.
+ // Monitor.Exit will then correctly take the slow path, find that the object is not locked,
+ // and throw.
+ try {
+ for (var i = 0; i < arr.Length; i++)
+ lock (arr[i])
+ GC.KeepAlive(arr[i]);
+ } catch (SynchronizationLockException) {
+ ok = false;
+ }
+
+ Console.WriteLine(ok ? "Test passed" : FailMsg);
+ return ok ? 100 : -1;
+ }
+}
diff --git a/tests/src/baseservices/threading/regressions/269336/objmonhelper.csproj b/tests/src/baseservices/threading/regressions/269336/objmonhelper.csproj
new file mode 100644
index 0000000000..51c8d711e7
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/269336/objmonhelper.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ObjMonHelper.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/269336/project.json b/tests/src/baseservices/threading/regressions/269336/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/269336/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/30032/30032.cs b/tests/src/baseservices/threading/regressions/30032/30032.cs
new file mode 100644
index 0000000000..caf979e6b8
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/30032/30032.cs
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+
+public class Test {
+
+ public static int Main(){
+
+ int rValue = 100;
+ Timer[] tArray = new Timer[100];
+ int val = 0;
+ while(val < 10){
+ try{
+ Interlocked.Increment(ref val);
+ Console.WriteLine("Loop {0}",val);
+ for(int i = 0;i<tArray.Length;i++)
+ tArray[i] = new Timer(new TimerCallback(TFunc),0,1000,100000000);
+
+ Thread.Sleep(1000);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ }
+ catch(Exception e){
+ Console.WriteLine(e.ToString());
+ rValue = -1;
+ }
+ }
+ Console.WriteLine("Test {0}",100 == rValue ? "Passed":"Failed");
+ return rValue;
+ }
+
+ public static void TFunc(Object o)
+ {
+ Thread.Sleep(1);
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/30032/30032.csproj b/tests/src/baseservices/threading/regressions/30032/30032.csproj
new file mode 100644
index 0000000000..5a2968d055
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/30032/30032.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="30032.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/30032/app.config b/tests/src/baseservices/threading/regressions/30032/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/30032/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/regressions/30032/project.json b/tests/src/baseservices/threading/regressions/30032/project.json
new file mode 100644
index 0000000000..344736691a
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/30032/project.json
@@ -0,0 +1,34 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Threading.Timer": "4.0.0-rc3-23823",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/beta1/322338.cs b/tests/src/baseservices/threading/regressions/beta1/322338.cs
new file mode 100644
index 0000000000..97be8b94ba
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta1/322338.cs
@@ -0,0 +1,111 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class Test
+{
+ public bool FinallyCalled;
+ public int RunLength;
+ public int SpecificWait;
+
+ static public int Main(string[] args)
+ {
+ if(args.Length < 1)
+ {
+ Console.WriteLine("Must supply run length");
+ return 10;
+ }
+
+ Test T = new Test();
+ T.SpecificWait = 0;
+ T.RunLength = Int32.Parse(args[0]);
+ if(args.Length == 2)
+ {
+ T.SpecificWait = Int32.Parse(args[1]);
+ }
+ int retVal = T.Run();
+ Console.WriteLine(100 == retVal ? "Test Passed":"Test Failed");
+ return retVal;
+ }
+
+ public int Run()
+ {
+ Thread NewThread = null;
+ Random RandomWait = new Random();
+ int Runs = 0;
+
+ FinallyCalled = true;
+
+ for (int i = 0; i< RunLength; i++)
+ {
+ // Create new Thread for test and start it
+ NewThread = new Thread( new ThreadStart(TestFinally ) );
+ NewThread.Start();
+ // Wait random period of time for thread
+ int wait;
+ if(SpecificWait == 0)
+ {
+ wait = RandomWait.Next();
+ wait = wait % 2000;
+ }
+ else
+ {
+ wait = SpecificWait;
+ }
+
+ Console.WriteLine("Testing with {0}", wait);
+ Thread.Sleep( wait );
+
+ // Abort thread, and wait to finish
+ ThreadEx.Abort(NewThread);
+ NewThread.Join();
+
+ Console.WriteLine(" Finshed run #{0}", Runs++ );
+
+ // Test if finally was called
+ if ( FinallyCalled != true )
+ {
+ Console.WriteLine("FAILURE!!! Finally was not hit, or this would be true");
+ return 5;
+ }
+ }
+ return 100;
+ }
+
+ public void TestFinally()
+ {
+ try
+ {
+ // We have set FinallyCalled to false, so if we are aborted this should
+ // be set to true no matter what!! (this is the bug)
+ FinallyCalled = false;
+
+ // Loop until this thread is aborted
+ while ( true )
+ {
+ CallTryTest();
+ }
+ }
+ finally
+ {
+ // This should be called no matter what
+ FinallyCalled = true;
+ }
+ }
+
+ private void CallTryTest()
+ {
+ try
+ {
+ // Do Something/Work (this could be anything)
+ FinallyCalled = false;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught exception '{0}'", e.Message );
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/beta1/322338.csproj b/tests/src/baseservices/threading/regressions/beta1/322338.csproj
new file mode 100644
index 0000000000..5b6b350d48
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta1/322338.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>240</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="322338.cs" />
+ <Compile Include="..\threadex.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/beta1/347011.cs b/tests/src/baseservices/threading/regressions/beta1/347011.cs
new file mode 100644
index 0000000000..fa0377b6aa
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta1/347011.cs
@@ -0,0 +1,35 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class TimerTest
+{
+ public static void Target(Object foo){}
+
+ public static int Main()
+ {
+ int retVal = 0;
+ Timer timer = new Timer(new TimerCallback(Target),new Object(), 1000,1000);
+ timer.Dispose();
+ try
+ {
+ timer.Change(5000,5000);
+ retVal = -5;
+ }
+ catch(ObjectDisposedException)
+ {
+ Console.WriteLine("Caught Expected exception");
+ retVal = 100;
+ }
+ catch(Exception ex)
+ {
+ Console.WriteLine("Unexpected exception: " + ex.ToString());
+ retVal = -1;
+ }
+ Console.WriteLine(100 == retVal ? "Test Passed":"Test Failed");
+ return retVal;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/beta1/347011.csproj b/tests/src/baseservices/threading/regressions/beta1/347011.csproj
new file mode 100644
index 0000000000..260f9f1085
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta1/347011.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>240</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="347011.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/beta1/app.config b/tests/src/baseservices/threading/regressions/beta1/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta1/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/regressions/beta1/project.json b/tests/src/baseservices/threading/regressions/beta1/project.json
new file mode 100644
index 0000000000..344736691a
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta1/project.json
@@ -0,0 +1,34 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Threading.Timer": "4.0.0-rc3-23823",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/beta2/417296_abort.cs b/tests/src/baseservices/threading/regressions/beta2/417296_abort.cs
new file mode 100644
index 0000000000..782bfdb73d
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta2/417296_abort.cs
@@ -0,0 +1,102 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+/*
+ * Test case verifies that when we take a thread abort exception
+ * while blocked waiting to re-acquire a monitor after doing a Monitor.Wait
+ * that we do not allow the thread to run again until the first thread
+ * has released it's lock.
+ *
+ */
+class Test
+{
+ object someLock = new object();
+ volatile bool thread1Locked = false, thread2exception = false;
+ int success = 100;
+
+ static int Main()
+ {
+ return(new Test().RunTest());
+ }
+
+ int RunTest()
+ {
+ Console.WriteLine ("Main thread starting");
+ Thread secondThread = new Thread (new ThreadStart(ThreadJob));
+ secondThread.Start();
+ Console.WriteLine ("Main thread sleeping");
+ Thread.Sleep(500);
+ lock (someLock)
+ {
+ thread1Locked = true;
+ Console.WriteLine ("Main thread acquired lock - pulsing monitor");
+ Monitor.Pulse(someLock);
+ Console.WriteLine ("Monitor pulsed; interrupting second thread");
+ ThreadEx.Abort(secondThread);
+ Thread.Sleep(1000);
+ Console.WriteLine ("Main thread still owns lock...");
+ Thread.Sleep(2000);
+ Console.WriteLine ("Main thread still owns lock...");
+ thread1Locked = false;
+ if(thread2exception)
+ {
+ Console.WriteLine("Thread2 took exception too early");
+ success = 95;
+ }
+ }
+ secondThread.Join();
+ if(success == 100)
+ {
+ Console.WriteLine("Test passed");
+ }
+ else
+ {
+ Console.WriteLine("Test failed");
+ }
+ return(success);
+ }
+
+ void ThreadJob()
+ {
+ Console.WriteLine ("Second thread starting");
+
+ lock (someLock)
+ {
+ Console.WriteLine ("Second thread acquired lock - about to wait");
+ try
+ {
+ Monitor.Wait(someLock);
+ }
+ catch (Exception e)
+ {
+ thread2exception = true;
+ if(thread1Locked)
+ {
+ success = 98;
+ }
+ Console.WriteLine ("Second thread caught an exception: {0}", e);
+ if(Monitor.TryEnter(someLock))
+ {
+ Console.WriteLine("Thread2 holds the lock");
+ Monitor.Exit(someLock);
+ }
+ else
+ {
+ Console.WriteLine("Couldn't recurse on lock");
+ success = 97;
+ }
+
+ if(!(e.GetType().ToString().Equals("System.Threading.ThreadAbortException")))
+ {
+ Console.WriteLine("Wrong exception: {0}",e);
+ success = 92;
+ }
+ }
+ }
+ }
+}
+
diff --git a/tests/src/baseservices/threading/regressions/beta2/417296_abort.csproj b/tests/src/baseservices/threading/regressions/beta2/417296_abort.csproj
new file mode 100644
index 0000000000..7f8f904aae
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta2/417296_abort.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="417296_abort.cs" />
+ <Compile Include="..\threadex.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/beta2/437017.cs b/tests/src/baseservices/threading/regressions/beta2/437017.cs
new file mode 100644
index 0000000000..284a5ae8df
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta2/437017.cs
@@ -0,0 +1,125 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class Test
+{
+ static bool _fTestFailed = false;
+ static bool _fTestDone = false;
+ static ManualResetEvent _mre;
+ static AutoResetEvent _are = new AutoResetEvent(false);
+
+ public static int Main(string[] args)
+ {
+ Thread th = new Thread(new ThreadStart(Thread2));
+ th.Start();
+ Thread th2 = new Thread(new ThreadStart(Thread3));
+ th2.Start();
+ System.Diagnostics.Stopwatch myTimer = new System.Diagnostics.Stopwatch();
+ myTimer.Start();
+
+ int i = 0;
+ while (!_fTestFailed && myTimer.Elapsed.Minutes < 5 && i < 25000)
+ {
+ i++;
+ ManualResetEvent mre = new ManualResetEvent(false);
+ _mre = new ManualResetEvent(false);
+ RegisteredWaitHandle rwh = ThreadPool.RegisterWaitForSingleObject(mre, new WaitOrTimerCallback(callback), null, -1, false);
+ _are.Set();
+
+ bool bUnregisterSucceeded = false; //Used to improve speed of the test when Unregister has failed
+ try
+ {
+ rwh.Unregister(_mre);
+ bUnregisterSucceeded = true;
+ }
+ catch (ObjectDisposedException)
+ {
+ }
+
+ if (bUnregisterSucceeded)
+ {
+ try
+ {
+ if (_mre.WaitOne(0))
+ {
+ Console.Write("@");
+ }
+ }
+ catch (ObjectDisposedException)
+ {
+ }
+ }
+
+ if (i % 100 == 0) Console.WriteLine(i);
+ }
+ _fTestDone = true;
+ _are.Set();
+ th.Join();
+ th2.Join();
+
+ if (!_fTestFailed)
+ {
+ Console.WriteLine("Test Passed");
+ return 100;
+ }
+
+ Console.WriteLine("Test Failed");
+ return 101;
+
+ }
+
+ static void callback(object state, bool fTimedOut)
+ {
+ Console.Write("!");
+ _fTestFailed = true;
+ }
+
+ public static void Thread3()
+ {
+ while (true & !_fTestDone)
+ {
+ _are.WaitOne();
+ _mre.Dispose();
+ }
+ }
+
+ public static void Thread2()
+ {
+ while (true & !_fTestDone)
+ {
+ Console.Write("#");
+ AutoResetEvent are;
+ using (are = new AutoResetEvent(false))
+ {
+ if (are.WaitOne(0))
+ {
+ Console.WriteLine("ARE Signaled!");
+ _fTestFailed = true;
+ }
+ }
+
+ using (are = new AutoResetEvent(false))
+ {
+ if (are.WaitOne(0))
+ {
+ Console.WriteLine("ARE Signaled!");
+ _fTestFailed = true;
+ }
+ }
+
+ using(are = new AutoResetEvent(false))
+ {
+ if (are.WaitOne(0))
+ {
+ Console.WriteLine("ARE Signaled!");
+ _fTestFailed = true;
+ }
+ }
+ }
+ }
+}
+
diff --git a/tests/src/baseservices/threading/regressions/beta2/437017.csproj b/tests/src/baseservices/threading/regressions/beta2/437017.csproj
new file mode 100644
index 0000000000..785be8b6bb
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta2/437017.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="437017.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/beta2/437044.cs b/tests/src/baseservices/threading/regressions/beta2/437044.cs
new file mode 100644
index 0000000000..9da799fc90
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta2/437044.cs
@@ -0,0 +1,119 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class Test
+{
+ static bool _fTestFailed = false;
+ static bool _fTestDone = false;
+ static ManualResetEvent _mre;
+ static AutoResetEvent _are = new AutoResetEvent(false);
+
+ public static int Main(string[] args)
+ {
+ Thread th = new Thread(new ThreadStart(Thread2));
+ th.Start();
+ Thread th2 = new Thread(new ThreadStart(Thread3));
+ th2.Start();
+
+ for (int i = 0; i < 20000 && !_fTestFailed; i++)
+ {
+ _mre = new ManualResetEvent(false);
+ Timer t = new Timer(new TimerCallback(callback), null, 1000000, Timeout.Infinite);
+ _are.Set();
+
+ bool bDisposeSucceeded = false; //Used to improve speed of the test when Dispose has failed
+ try
+ {
+ t.Dispose();
+ bDisposeSucceeded = true;
+ }
+ catch (ObjectDisposedException)
+ {
+ }
+
+ if (bDisposeSucceeded)
+ {
+ try
+ {
+ if (_mre.WaitOne(0))
+ {
+ Console.Write("@");
+ }
+ }
+ catch (ObjectDisposedException)
+ {
+ }
+ }
+ }
+ _fTestDone = true;
+ _are.Set();
+ th.Join();
+ th2.Join();
+
+ if (!_fTestFailed)
+ {
+ Console.WriteLine("Test Passed");
+ return 100;
+ }
+
+ Console.WriteLine("Test Failed");
+ return 101;
+
+ }
+
+ static void callback(object state)
+ {
+ Console.Write("!");
+ _fTestFailed = true;
+ }
+
+ public static void Thread3()
+ {
+ while (true & !_fTestDone)
+ {
+ _are.WaitOne();
+ _mre.Dispose();
+ }
+ }
+
+ public static void Thread2()
+ {
+ while (true & !_fTestDone)
+ {
+ Console.Write("#");
+ AutoResetEvent are;
+
+ using(are = new AutoResetEvent(false))
+ {
+ if (are.WaitOne(0))
+ {
+ Console.WriteLine("ARE Signaled!");
+ _fTestFailed = true;
+ }
+ }
+
+ using(are = new AutoResetEvent(false))
+ {
+ if (are.WaitOne(0))
+ {
+ Console.WriteLine("ARE Signaled!");
+ _fTestFailed = true;
+ }
+ }
+
+ using(are = new AutoResetEvent(false))
+ {
+ if (are.WaitOne(0))
+ {
+ Console.WriteLine("ARE Signaled!");
+ _fTestFailed = true;
+ }
+ }
+ }
+ }
+}
+
diff --git a/tests/src/baseservices/threading/regressions/beta2/437044.csproj b/tests/src/baseservices/threading/regressions/beta2/437044.csproj
new file mode 100644
index 0000000000..724c36955f
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta2/437044.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="437044.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/beta2/app.config b/tests/src/baseservices/threading/regressions/beta2/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta2/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/regressions/beta2/project.json b/tests/src/baseservices/threading/regressions/beta2/project.json
new file mode 100644
index 0000000000..344736691a
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/beta2/project.json
@@ -0,0 +1,34 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Threading.Timer": "4.0.0-rc3-23823",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/devdiv489437/app.config b/tests/src/baseservices/threading/regressions/devdiv489437/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/devdiv489437/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/regressions/devdiv489437/project.json b/tests/src/baseservices/threading/regressions/devdiv489437/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/devdiv489437/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/devdiv489437/test489437.cs b/tests/src/baseservices/threading/regressions/devdiv489437/test489437.cs
new file mode 100644
index 0000000000..8b3754f704
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/devdiv489437/test489437.cs
@@ -0,0 +1,52 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+/*
+ * Issue description:
+ If a SemaphoreSlim.WaitAsync call is cancelled just after Release has
+ caused it to start to complete, we end up decrementing the semaphore's
+ count *and* cancelling the task. The caller does not know the count has
+ been decremented, because the call appears to fail. This leads to
+ deadlock later, because the caller has no reason to believe it should
+ release the erroneously-acquired count.
+
+Change description:
+ If the operation has already begun completing successfully, do not
+ cancel the associated Task.
+*/
+
+class Test
+{
+ static int Main(string[] args)
+ {
+ SemaphoreSlim s = new SemaphoreSlim(initialCount: 1);
+
+ var cts = new CancellationTokenSource();
+ s.Wait();
+ var t = s.WaitAsync(cts.Token);
+ s.Release();
+ cts.Cancel();
+
+
+ if (t.Status != TaskStatus.Canceled && s.CurrentCount == 0)
+ {
+ Console.WriteLine("PASS");
+ return 100;
+ }
+ else
+ {
+ Console.WriteLine("FAIL");
+ Console.WriteLine("Expected task status to not be Canceled and s.CurrentCount == 0");
+ Console.WriteLine("Actual: Task: " + t.Status + "; CurrentCount: " + s.CurrentCount);
+ return 101;
+ }
+
+
+ }
+}
+
diff --git a/tests/src/baseservices/threading/regressions/devdiv489437/test489437.csproj b/tests/src/baseservices/threading/regressions/devdiv489437/test489437.csproj
new file mode 100644
index 0000000000..f5f4d8f05c
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/devdiv489437/test489437.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="test489437.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/m2/91848.cs b/tests/src/baseservices/threading/regressions/m2/91848.cs
new file mode 100644
index 0000000000..9d86e8f601
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/m2/91848.cs
@@ -0,0 +1,78 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+
+public class TestRudeAbort {
+
+ public int rValue;
+
+ public TestRudeAbort()
+ {
+ rValue = 0;
+ }
+
+ public static int Main() {
+
+ TestRudeAbort myTest = new TestRudeAbort();
+ myTest.ExecuteTest();
+ Console.WriteLine("Test {0}",myTest.rValue == 100 ? "paSSed":"failed");
+ return myTest.rValue;
+
+ }
+
+ public void ExecuteTest()
+ {
+ Thread t = new Thread(new ThreadStart(this.ThrowInStatic));
+ t.Start();
+ t.Join();
+ try{
+ //Thread is dead - Try to access Static Method
+ // This call should fail since the constructor never ran
+ SBad.MyMethod();
+ //If we got here, we accessed an unitialized class
+ Console.WriteLine("ERRROR -- Accessed the class");
+ lock(this) this.rValue = -1;
+ SBad.Obj.ToString();
+ //If we got here, we accessed an unitialized class
+ Console.WriteLine("ERRROR -- Accessed the class");
+ lock(this) this.rValue = -2;
+ }
+ catch(TypeInitializationException){
+ //Caught TypeInit Exception as expected
+ Interlocked.CompareExchange(ref this.rValue,100,0);
+ }
+ }
+
+ public void ThrowInStatic()
+ {
+ try{
+ SBad.MyMethod();
+ }
+ catch(TypeInitializationException)
+ {
+ //This is expected
+ }
+ Console.WriteLine("ERROR --- This line will never print since the thread aborted()");
+ lock(this) this.rValue = -5;
+ }
+}
+
+public class SBad
+{
+ public static Object Obj = null;
+ static SBad(){
+ //Console.WriteLine("In the Constructor");
+ ThreadEx.Abort(Thread.CurrentThread);
+ Console.WriteLine("After Abort");
+ Obj = new Object();
+ }
+
+ public static void MyMethod()
+ {
+ Console.WriteLine("ERROR --- Should have been type Load");
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/m2/91848.csproj b/tests/src/baseservices/threading/regressions/m2/91848.csproj
new file mode 100644
index 0000000000..7cd7501cf3
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/m2/91848.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="91848.cs" />
+ <Compile Include="..\threadex.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/m2/app.config b/tests/src/baseservices/threading/regressions/m2/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/m2/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/regressions/m2/project.json b/tests/src/baseservices/threading/regressions/m2/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/m2/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/m2/tastaticconst.cs b/tests/src/baseservices/threading/regressions/m2/tastaticconst.cs
new file mode 100644
index 0000000000..df91832f23
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/m2/tastaticconst.cs
@@ -0,0 +1,70 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+
+public class TestRudeAbort {
+
+ public int rValue;
+
+ public TestRudeAbort(){
+
+ rValue = 0;
+ }
+
+ public static int Main() {
+
+ //If Static Constructor Fails to run the struct should not get loaded
+
+ TestRudeAbort tra = new TestRudeAbort();
+ Thread t = new Thread(new ThreadStart(tra.Run));
+ t.Start();
+ t.Join();
+ try{
+ Console.WriteLine("Thread is dead - Accessing Static Method");
+ SBad.MyMethod();
+ SBad.Obj.ToString();
+ }
+ catch(TypeInitializationException){
+ //Should get a TypeInitializationException since the
+ // static constructor never ran.
+ //If no failure i.e. rValue == 0 then set return to 100
+ Interlocked.CompareExchange(ref tra.rValue,100,0);
+ }
+ Console.WriteLine("Test {0}",tra.rValue == 100?"Passed":"Failed");
+ return tra.rValue;
+ }
+
+ public void Run()
+ {
+ try{
+ SBad.MyMethod();
+ }
+ catch(TypeInitializationException)
+ {
+ //This should never print anything since the thread is Aborted
+ this.rValue = -1;
+ }
+ Console.WriteLine("This line should never print since the thread aborted()");
+ this.rValue = -2;
+ }
+}
+
+public struct SBad
+{
+ public static Object Obj = null;
+ static SBad(){
+ //Console.WriteLine("In the Constructor");
+ ThreadEx.Abort(Thread.CurrentThread);
+ Console.WriteLine("After Abort");
+ Obj = new Object();
+ }
+
+ public static void MyMethod()
+ {
+ Console.WriteLine("Should have been type Load");
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/m2/tastaticconst.csproj b/tests/src/baseservices/threading/regressions/m2/tastaticconst.csproj
new file mode 100644
index 0000000000..71b3f1c163
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/m2/tastaticconst.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="TAStaticConst.cs" />
+ <Compile Include="..\threadex.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/threadex.cs b/tests/src/baseservices/threading/regressions/threadex.cs
new file mode 100644
index 0000000000..f57a094be7
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/threadex.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Threading;
+using System.Reflection;
+
+public class ThreadEx
+{
+ public static void Abort(Thread thread)
+ {
+ MethodInfo abort = null;
+ foreach(MethodInfo m in thread.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
+ {
+ if (m.Name.Equals("AbortInternal") && m.GetParameters().Length == 0) abort = m;
+ }
+ if (abort == null)
+ {
+ throw new Exception("Failed to get Thread.Abort method");
+ }
+ abort.Invoke(thread, new object[0]);
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/whidbey_m3/105019.cs b/tests/src/baseservices/threading/regressions/whidbey_m3/105019.cs
new file mode 100644
index 0000000000..301176162f
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/whidbey_m3/105019.cs
@@ -0,0 +1,57 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class Stop
+{
+
+ int av;
+ AutoResetEvent are = new AutoResetEvent(false);
+
+ unsafe public void T1Start()
+ {
+ are.Set();
+ for (; ; )
+ {
+ try
+ {
+ int* p = null;
+ *p = 1;
+ }
+ catch
+ {
+ av++;
+ }
+ }
+ }
+
+ public static int Main(String[] args)
+ {
+ Stop tm = new Stop();
+ Thread t = new Thread(new ThreadStart(tm.RunTest));
+ t.Start();
+ //Sleep for 3 minutes
+ Thread.Sleep(3 * 60 * 1000);
+ ThreadEx.Abort(t);
+ return 100;
+
+ }
+ public void RunTest()
+ {
+ ThreadStart ts = new ThreadStart(this.T1Start);
+ for (; ; )
+ {
+ Thread t1 = new Thread(ts);
+ t1.IsBackground = true;
+ t1.Start();
+ are.WaitOne();
+ Console.WriteLine("Aborting t1 " + this.av);
+ ThreadEx.Abort(t1);
+ Console.WriteLine("Aborted");
+ }
+
+ }
+}
diff --git a/tests/src/baseservices/threading/readerwriterlockslim/Upgrader.csproj b/tests/src/baseservices/threading/regressions/whidbey_m3/105019.csproj
index 9f9937cff2..217807c804 100644
--- a/tests/src/baseservices/threading/readerwriterlockslim/Upgrader.csproj
+++ b/tests/src/baseservices/threading/regressions/whidbey_m3/105019.csproj
@@ -14,9 +14,6 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -30,7 +27,8 @@
</ItemGroup>
<ItemGroup>
<!-- Add Compile Object Here -->
- <Compile Include="upgrader.cs" />
+ <Compile Include="105019.cs" />
+ <Compile Include="..\threadex.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
@@ -39,9 +37,6 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
- <ItemGroup>
- <ProjectReference Include="../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
</PropertyGroup>
diff --git a/tests/src/baseservices/threading/regressions/whidbey_m3/200176.cs b/tests/src/baseservices/threading/regressions/whidbey_m3/200176.cs
new file mode 100644
index 0000000000..6a053a1301
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/whidbey_m3/200176.cs
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+public class Stop {
+
+ public static int Main(String[] args) {
+
+ Stop tm = new Stop();
+ try
+ {
+
+ ThreadPool.QueueUserWorkItem(new WaitCallback(tm.RunTest));
+ Thread.Sleep(3000);
+ }
+ catch
+ {
+ return -1;
+ }
+ return 100;
+ }
+ public void RunTest(object foo)
+ {
+ try{
+ throw new Exception();
+ }
+ catch
+ {}
+ }
+}
diff --git a/tests/src/baseservices/threading/regressions/whidbey_m3/200176.csproj b/tests/src/baseservices/threading/regressions/whidbey_m3/200176.csproj
new file mode 100644
index 0000000000..8306ab81c1
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/whidbey_m3/200176.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="200176.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/regressions/whidbey_m3/app.config b/tests/src/baseservices/threading/regressions/whidbey_m3/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/whidbey_m3/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/regressions/whidbey_m3/project.json b/tests/src/baseservices/threading/regressions/whidbey_m3/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/regressions/whidbey_m3/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/app.config b/tests/src/baseservices/threading/semaphore/ctoropen/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/project.json b/tests/src/baseservices/threading/semaphore/ctoropen/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector1.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector1.cs
new file mode 100644
index 0000000000..cd13936ada
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector1.cs
@@ -0,0 +1,69 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class CtorTest
+{
+ public static int Main(string[] args)
+ {
+ // Check args
+ if (args.Length != 2)
+ {
+ Console.WriteLine("USAGE: SemaphoreCtor1 /iCount:<int> /mCount:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iCount = -1, mCount = -1;
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i].ToLower().StartsWith("/icount:"))
+ {
+ iCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/mcount:"))
+ {
+ mCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+ }
+ CtorTest ct = new CtorTest();
+ return ct.Run(iCount, mCount);
+ }
+
+ private int Run(int iCount, int mCount)
+ {
+ // Testing basic scenario
+ int iRet = -1;
+ Semaphore sem = null;
+ try
+ {
+ using (sem = new Semaphore(iCount, mCount))
+ {
+ int iPrev = 0, count = iCount;
+ // Do a wait one if we can
+ if (iCount > 0)
+ {
+ sem.WaitOne();
+ count--;
+ }
+ iPrev = sem.Release();
+
+ if (iPrev == count)
+ iRet = 100;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("FAIL: CtorTest1(" + iCount + "," + mCount + ") - Unexpected exception thrown: " + ex.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector1.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector1.csproj
new file mode 100644
index 0000000000..0c29d8d0ce
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector1.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/iCount:2147483647 /mCount:2147483647</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreCtor1.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector2.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector2.cs
new file mode 100644
index 0000000000..060c9f8de5
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector2.cs
@@ -0,0 +1,99 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class CtorTest
+{
+ public static int Main(string[] args)
+ {
+ // Check args
+ if (args.Length < 2)
+ {
+ Console.WriteLine("USAGE: SemaphoreCtor2 /iCount:<int> /mCount:<int> " +
+ "[/semName:<string>] [/iRandom:<int>]");
+ return -1;
+ }
+
+ // Get the args
+ int iCount = -1, mCount = -1, iRandom = -1;
+ string semName = "DefaultString";
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i].ToLower().StartsWith("/icount:"))
+ {
+ iCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/mcount:"))
+ {
+ mCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/irandom:"))
+ {
+ iRandom = Convert.ToInt32(args[i].Substring(9));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/semname:"))
+ {
+ semName = args[i].Substring(9);
+ if (semName.ToLower() == "null")
+ semName = null;
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/unisemname:"))
+ {
+ semName = string.Empty;
+ // Convert to unicode
+ string[] s = args[i].Substring(12).Split(';');
+ foreach (string str in s)
+ semName += Convert.ToChar(Convert.ToInt32(str));
+ continue;
+ }
+ }
+ CtorTest ct = new CtorTest();
+ return ct.Run(iCount, mCount, semName, iRandom);
+ }
+
+ private int Run(int iCount, int mCount, string semName, int iRandom)
+ {
+ // Testing basic string scenario
+ int iRet = -1, count = iCount;
+ Semaphore sem1 = null, sem2 = null;
+ if (iRandom > 0)
+ semName = Common.GenerateUnicodeString(iRandom);
+ try
+ {
+ using (sem1 = new Semaphore(iCount, mCount, semName))
+ {
+ using (sem2 = (semName != null && semName != string.Empty) ? Semaphore.OpenExisting(semName) : sem1)
+ {
+ if (iCount > 0)
+ {
+ sem2.WaitOne();
+ count--;
+ }
+
+ int iPrev = sem2.Release();
+
+ if (iPrev == count)
+ iRet = 100;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + ex.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector2.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector2.csproj
new file mode 100644
index 0000000000..d562ea4275
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector2.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/iCount:0 /mCount:1 /semName:MySemaphoreName</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreCtor2.cs" />
+ <Compile Include="..\SemaphoreCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector3.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector3.cs
new file mode 100644
index 0000000000..52144bc138
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector3.cs
@@ -0,0 +1,128 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class CtorTest
+{
+ public static int Main(string[] args)
+ {
+ // Check args
+ if (args.Length < 2)
+ {
+ Console.WriteLine("USAGE: SemaphoreCtor3 /iCount:<int> /mCount:<int> " +
+ "[/semName:<string>] [/iRandom:<int>]");
+ return -1;
+ }
+
+ // Get the args
+ int iCount = -1, mCount = -1, iRandom = -1;
+ string semName = "DefaultString";
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i].ToLower().StartsWith("/icount:"))
+ {
+ iCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/mcount:"))
+ {
+ mCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/irandom:"))
+ {
+ iRandom = Convert.ToInt32(args[i].Substring(9));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/semname:"))
+ {
+ semName = args[i].Substring(9);
+ if (semName.ToLower() == "null")
+ semName = null;
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/unisemname:"))
+ {
+ semName = string.Empty;
+ // Convert to unicode
+ string[] s = args[i].Substring(12).Split(';');
+ foreach (string str in s)
+ semName += Convert.ToChar(Convert.ToInt32(str));
+ continue;
+ }
+ }
+ CtorTest ct = new CtorTest();
+ return ct.Run(iCount, mCount, semName, iRandom);
+ }
+
+ private int Run(int iCount, int mCount, string semName, int iRandom)
+ {
+ // Testing overlap of long strings
+ int iRet = -1;
+ Semaphore sem1 = null, sem2 = null, sem3 = null,
+ sem4 = null, sem6 = null;
+ if (iRandom > 0)
+ {
+ //TestFramework.GlobalData intl = new TestFramework.GlobalData();
+ //semName = intl.GetString(iRandom, iRandom).Replace(@"\", "");
+ Console.WriteLine("WARNING: No random name generation is ocurring");
+ }
+ string semNewName = semName.Remove(semName.Length - 2, 1);
+ try
+ {
+ // Create slightly different names
+ using (sem1 = new Semaphore(iCount, mCount, semName))
+ {
+ sem2 = new Semaphore(iCount, mCount, semNewName);
+ // Make sure we can open it
+ using(sem3 = Semaphore.OpenExisting(semName))
+ {
+ sem4 = Semaphore.OpenExisting(semNewName);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + ex.ToString());
+ Console.WriteLine("Test Failed");
+ return iRet;
+ }
+
+ // Make sure you can't open it
+ try
+ {
+ Semaphore sem5 = Semaphore.OpenExisting(semName);
+ }
+ catch (WaitHandleCannotBeOpenedException)
+ {
+ // This is expected
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ Console.WriteLine("Test Failed");
+ return iRet;
+ }
+
+ // Make sure you can still open the other one
+ sem6 = Semaphore.OpenExisting(semNewName);
+ // Do a wait and release
+ sem6.WaitOne();
+ sem6.Release();
+ iRet = 100;
+
+ //Add a subsequent use of sem2 to avoid system event be GCed.
+ GC.KeepAlive(sem2);
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector3.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector3.csproj
new file mode 100644
index 0000000000..033d1e27b1
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector3.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/iCount:10 /mCount:10 /semname:abcdefghijklmnopqrstuvwxyz</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreCtor3.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector4.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector4.cs
new file mode 100644
index 0000000000..fff49e49ef
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector4.cs
@@ -0,0 +1,97 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class CtorTest
+{
+ public static int Main(string[] args)
+ {
+ // Check args
+ if (args.Length < 2)
+ {
+ Console.WriteLine("USAGE: SemaphoreCtor4 /iCount:<int> /mCount:<int> " +
+ "[/semName:<string>] [/iRandom:<int>]");
+ return -1;
+ }
+
+ // Get the args
+ int iCount = -1, mCount = -1, iRandom = -1;
+ string semName = "DefaultString";
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i].ToLower().StartsWith("/icount:"))
+ {
+ iCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/mcount:"))
+ {
+ mCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/irandom:"))
+ {
+ iRandom = Convert.ToInt32(args[i].Substring(9));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/semname:"))
+ {
+ semName = args[i].Substring(9);
+ if (semName.ToLower() == "null")
+ semName = null;
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/unisemname:"))
+ {
+ semName = string.Empty;
+ // Convert to unicode
+ string[] s = args[i].Substring(12).Split(';');
+ foreach (string str in s)
+ semName += Convert.ToChar(Convert.ToInt32(str));
+ continue;
+ }
+ }
+ CtorTest ct = new CtorTest();
+ return ct.Run(iCount, mCount, semName, iRandom);
+ }
+
+ private int Run(int iCount, int mCount, string semName, int iRandom)
+ {
+ // Testing createdNew
+ bool createdNew;
+ int iRet = -1, count = iCount;
+ Semaphore sem = null;
+ if (iRandom > 0)
+ semName = Common.GenerateUnicodeString(iRandom);
+ try
+ {
+ using(sem = new Semaphore(iCount, mCount, semName, out createdNew))
+ {
+ if (iCount > 0)
+ {
+ sem.WaitOne();
+ count--;
+ }
+
+ int iPrev = sem.Release();
+ if (iPrev == count && createdNew)
+ iRet = 100;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + ex.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector4.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector4.csproj
new file mode 100644
index 0000000000..9b126895ab
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector4.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/iCount:3 /mCount:5 /iRandom:260</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreCtor4.cs" />
+ <Compile Include="..\SemaphoreCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector5.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector5.cs
new file mode 100644
index 0000000000..27bfb5c5b7
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector5.cs
@@ -0,0 +1,108 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class CtorTest
+{
+ public static int Main(string[] args)
+ {
+ // Check args
+ if (args.Length < 2)
+ {
+ Console.WriteLine("USAGE: SemaphoreCtor4 /iCount:<int> /mCount:<int> " +
+ "[/semName:<string>] [/iRandom:<int>]");
+ return -1;
+ }
+
+ // Get the args
+ int iCount = -1, mCount = -1, iRandom = -1;
+ string semName = "DefaultString";
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i].ToLower().StartsWith("/icount:"))
+ {
+ iCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/mcount:"))
+ {
+ mCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/irandom:"))
+ {
+ iRandom = Convert.ToInt32(args[i].Substring(9));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/semname:"))
+ {
+ semName = args[i].Substring(9);
+ if (semName.ToLower() == "null")
+ semName = null;
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/unisemname:"))
+ {
+ semName = string.Empty;
+ // Convert to unicode
+ string[] s = args[i].Substring(12).Split(';');
+ foreach (string str in s)
+ semName += Convert.ToChar(Convert.ToInt32(str));
+ continue;
+ }
+ }
+ CtorTest ct = new CtorTest();
+ return ct.Run(iCount, mCount, semName, iRandom);
+ }
+
+ private int Run(int iCount, int mCount, string semName, int iRandom)
+ {
+ // Testing createdNew
+ bool createdNew, createdNew2;
+ bool bResult = true;
+ int iRet = -1, count = iCount;
+ Semaphore sem1 = null, sem2 = null;
+ if (iRandom > 0)
+ semName = Common.GenerateUnicodeString(iRandom);
+ try
+ {
+ // Open one, createdNew = true
+ using (sem1 = new Semaphore(iCount, mCount, semName, out createdNew))
+ {
+ if (!createdNew)
+ bResult = false;
+ // Open another, createdNew = false
+ using (sem2 = new Semaphore(iCount, mCount, semName, out createdNew2))
+ {
+ if (createdNew2)
+ bResult = false;
+
+ if (iCount > 0)
+ {
+ sem2.WaitOne();
+ count--;
+ }
+
+ int iPrev = sem2.Release();
+ if (bResult && iPrev == count)
+ iRet = 100;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + ex.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector5.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector5.csproj
new file mode 100644
index 0000000000..c70c987fe5
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorector5.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/iCount:2147483647 /mCount:2147483647 /iRandom:220</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreCtor5.cs" />
+ <Compile Include="..\SemaphoreCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg1.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg1.cs
new file mode 100644
index 0000000000..f9386e1813
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg1.cs
@@ -0,0 +1,65 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class CtorTest
+{
+ public static int Main(string[] args)
+ {
+ // Check args
+ if (args.Length != 2)
+ {
+ Console.WriteLine("USAGE: SemaphoreCtorNeg1 /iCount:<int> /mCount:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iCount = -1, mCount = -1;
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i].ToLower().StartsWith("/icount:"))
+ {
+ iCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/mcount:"))
+ {
+ mCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+ }
+ CtorTest ct = new CtorTest();
+ return ct.Run(iCount, mCount);
+ }
+
+ private int Run(int initCount, int maxCount)
+ {
+ int iRet = -1;
+ Semaphore sem = null;
+ try
+ {
+ using (sem = new Semaphore(initCount, maxCount))
+ {
+ Console.WriteLine("Semaphore was created!");
+ }
+ }
+ catch(ArgumentException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ // other exceptions are not valid
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg1.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg1.csproj
new file mode 100644
index 0000000000..974b5fa421
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg1.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/iCount:-2147483647 /mCount:2147483647</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreCtorNeg1.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg2.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg2.cs
new file mode 100644
index 0000000000..f99c8769b6
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg2.cs
@@ -0,0 +1,93 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class CtorTest
+{
+ public static int Main(string[] args)
+ {
+ // Check args
+ if (args.Length < 3)
+ {
+ Console.WriteLine("USAGE: SemaphoreCtorNeg2 /iCount:<int> /mCount:<int> " +
+ "/semName:<string> [/iRandom:<int>]");
+ return -1;
+ }
+
+ // Get the args
+ int iCount = -1, mCount = -1, iRandom = -1;
+ string semName = "DefaultString";
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i].ToLower().StartsWith("/icount:"))
+ {
+ iCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/mcount:"))
+ {
+ mCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/irandom:"))
+ {
+ iRandom = Convert.ToInt32(args[i].Substring(9));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/semname:"))
+ {
+ semName = args[i].Substring(9);
+ if (semName.ToLower() == "null")
+ semName = null;
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/unisemname:"))
+ {
+ semName = string.Empty;
+ // Convert to unicode
+ string[] s = args[i].Substring(12).Split(';');
+ foreach (string str in s)
+ semName += Convert.ToChar(Convert.ToInt32(str));
+ continue;
+ }
+ }
+ CtorTest ct = new CtorTest();
+ return ct.Run(iCount, mCount, semName, iRandom);
+ }
+
+ private int Run(int initalValue, int maxValue, string semName, int iRandom)
+ {
+ int iRet = -1;
+ Semaphore sem = null;
+ if (iRandom > 0)
+ semName = Common.GenerateUnicodeString(iRandom);
+ try
+ {
+ using (sem = new Semaphore(initalValue, maxValue, semName))
+ {
+ Console.WriteLine("Semaphore was created!");
+ }
+ }
+ catch(ArgumentException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg2.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg2.csproj
new file mode 100644
index 0000000000..271118766c
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg2.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/iCount:-1 /mCount:3 /semName:" "</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreCtorNeg2.cs" />
+ <Compile Include="..\SemaphoreCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg3.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg3.cs
new file mode 100644
index 0000000000..724853c552
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg3.cs
@@ -0,0 +1,103 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class CtorTest
+{
+ public static int Main(string[] args)
+ {
+ // Check args
+ if (args.Length < 3)
+ {
+ Console.WriteLine("USAGE: SemaphoreCtorNeg3 /iCount:<int> /mCount:<int> " +
+ "[/semName:<string>] [/iRandom:<int>]");
+ return -1;
+ }
+
+ // Get the args
+ int iCount = -1, mCount = -1, iRandom = -1;
+ string semName = "DefaultString";
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i].ToLower().StartsWith("/icount:"))
+ {
+ iCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/mcount:"))
+ {
+ mCount = Convert.ToInt32(args[i].Substring(8));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/irandom:"))
+ {
+ iRandom = Convert.ToInt32(args[i].Substring(9));
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/semname:"))
+ {
+ semName = args[i].Substring(9);
+ if (semName.ToLower() == "null")
+ semName = null;
+ continue;
+ }
+
+ if (args[i].ToLower().StartsWith("/unisemname:"))
+ {
+ semName = string.Empty;
+ // Convert to unicode
+ string[] s = args[i].Substring(12).Split(';');
+ foreach (string str in s)
+ semName += Convert.ToChar(Convert.ToInt32(str));
+ continue;
+ }
+ }
+ CtorTest ct = new CtorTest();
+ return ct.Run(iCount, mCount, semName, iRandom);
+ }
+
+ private int Run(int initalValue, int maxValue, string semName,
+ int iRandom)
+ {
+ int iRet = -1;
+ Semaphore sem = null;
+ if (iRandom > 0)
+ {
+ //TestFramework.GlobalData intl = new TestFramework.GlobalData();
+ //semName = intl.GetString(iRandom, iRandom).Replace(@"\", "");
+ Console.WriteLine("WARNING: Random name generation is disabled");
+ }
+ bool bRet=true;
+ try
+ {
+ using (sem = new Semaphore(initalValue, maxValue, semName, out bRet))
+ {
+ if(bRet)
+ Console.WriteLine("Semaphore was created!");
+ }
+ }
+ catch(ArgumentException)
+ {
+ // Expected
+ if(bRet)
+ iRet = 100;
+ else
+ Console.WriteLine("Returned FALSE");
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg3.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg3.csproj
new file mode 100644
index 0000000000..4416c248bd
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphorectorneg3.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/iCount:-2147483647 /mCount:-2147483647 /semName:null</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreCtorNeg3.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg1.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg1.cs
new file mode 100644
index 0000000000..d6bbb165a4
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg1.cs
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenSemaphoreNeg
+{
+ public static int Main()
+ {
+ OpenSemaphoreNeg osn = new OpenSemaphoreNeg();
+ return osn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Semaphore sem;
+ try
+ {
+ sem = Semaphore.OpenExisting(Common.GetUniqueName());
+ }
+ catch (WaitHandleCannotBeOpenedException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg1.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg1.csproj
new file mode 100644
index 0000000000..40e23a793a
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg1.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreOpenNeg1.cs" />
+ <Compile Include="..\SemaphoreCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg2.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg2.cs
new file mode 100644
index 0000000000..a5ea955c49
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg2.cs
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenSemaphoreNeg
+{
+ public static int Main()
+ {
+ OpenSemaphoreNeg osn = new OpenSemaphoreNeg();
+ return osn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Semaphore sem;
+ try
+ {
+ using (sem = Semaphore.OpenExisting(""))
+ {
+ }
+ }
+ catch (ArgumentException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg2.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg2.csproj
new file mode 100644
index 0000000000..102cc43a07
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg2.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreOpenNeg2.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg3.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg3.cs
new file mode 100644
index 0000000000..6194222068
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg3.cs
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenSemaphoreNeg
+{
+ public static int Main()
+ {
+ OpenSemaphoreNeg osn = new OpenSemaphoreNeg();
+ return osn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Semaphore sem;
+ try
+ {
+ sem = Semaphore.OpenExisting(null);
+ }
+ catch (ArgumentNullException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg3.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg3.csproj
new file mode 100644
index 0000000000..0909e1d930
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg3.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreOpenNeg3.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg4.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg4.cs
new file mode 100644
index 0000000000..45f5db5ca9
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg4.cs
@@ -0,0 +1,39 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenSemaphoreNeg
+{
+ public static int Main()
+ {
+ OpenSemaphoreNeg osn = new OpenSemaphoreNeg();
+ return osn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Semaphore sem;
+ try
+ {
+ String mySem = null;
+ sem = Semaphore.OpenExisting(mySem);
+ }
+ catch (ArgumentNullException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg4.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg4.csproj
new file mode 100644
index 0000000000..bce983cd2f
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg4.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreOpenNeg4.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg5.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg5.cs
new file mode 100644
index 0000000000..998c26179b
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg5.cs
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenSemaphoreNeg
+{
+ public static int Main()
+ {
+ OpenSemaphoreNeg osn = new OpenSemaphoreNeg();
+ return osn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ string sName = Common.GetUniqueName();
+ // open a closed semaphore
+ try
+ {
+ using (Semaphore sem1 = new Semaphore(10, 10, sName))
+ {
+ }
+ Semaphore sem2 = Semaphore.OpenExisting(sName);
+ }
+ catch (WaitHandleCannotBeOpenedException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg5.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg5.csproj
new file mode 100644
index 0000000000..79c193a853
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg5.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreOpenNeg5.cs" />
+ <Compile Include="..\SemaphoreCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg6.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg6.cs
new file mode 100644
index 0000000000..282c5c43d2
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg6.cs
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenSemaphoreNeg
+{
+ public static int Main()
+ {
+ OpenSemaphoreNeg osn = new OpenSemaphoreNeg();
+ return osn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ string sName = Common.GetUniqueName();
+ // open a semaphore with the same name as a mutex
+ Mutex mu = new Mutex(false, sName);
+ try
+ {
+ using (Semaphore sem = Semaphore.OpenExisting(sName))
+ {
+ }
+ }
+ catch (WaitHandleCannotBeOpenedException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg6.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg6.csproj
new file mode 100644
index 0000000000..0d44494858
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg6.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreOpenNeg6.cs" />
+ <Compile Include="..\SemaphoreCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.cs
new file mode 100644
index 0000000000..ff36723e14
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.cs
@@ -0,0 +1,43 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class OpenSemaphoreNeg
+{
+ public static int Main()
+ {
+ OpenSemaphoreNeg osn = new OpenSemaphoreNeg();
+ return osn.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ string sName = Common.GetUniqueName();
+ // open a semaphore with the same name as a mutex
+ EventWaitHandle ewh = new EventWaitHandle(false,
+ EventResetMode.AutoReset, sName);
+ try
+ {
+ using(Semaphore sem = Semaphore.OpenExisting(sName))
+ {
+ }
+ }
+ catch (WaitHandleCannotBeOpenedException)
+ {
+ //Expected
+ iRet = 100;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught unexpected exception: " +
+ e.ToString());
+ }
+
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.csproj b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.csproj
new file mode 100644
index 0000000000..6d653f38b5
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemaphoreOpenNeg7.cs" />
+ <Compile Include="..\SemaphoreCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/semaphorecommon.cs b/tests/src/baseservices/threading/semaphore/semaphorecommon.cs
new file mode 100644
index 0000000000..11f23caddb
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/semaphorecommon.cs
@@ -0,0 +1,36 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class Common
+{
+ public static string GenerateUnicodeString(int iNumChars)
+ {
+ Random rand = new Random();
+ string semName = string.Empty;
+ string semNameNum = string.Empty;
+ for (int i = 0; i < iNumChars; i++)
+ {
+ char c = '\\';
+ while (c == '\\')
+ {
+ c = (char)rand.Next(Char.MinValue, Char.MaxValue);
+ }
+ semNameNum += ((int)c).ToString() + ";";
+ semName += c;
+ }
+ // write to output
+ Console.WriteLine("Unicode string: " + semNameNum);
+ return semName;
+ }
+
+ public static string GetUniqueName()
+ {
+ string sName = Guid.NewGuid().ToString();
+ Console.WriteLine("Name created: " + sName);
+ return sName;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/unit/app.config b/tests/src/baseservices/threading/semaphore/unit/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/unit/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/semaphore/unit/project.json b/tests/src/baseservices/threading/semaphore/unit/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/unit/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/unit/semdemo.cs b/tests/src/baseservices/threading/semaphore/unit/semdemo.cs
new file mode 100644
index 0000000000..9dc502f0f1
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/unit/semdemo.cs
@@ -0,0 +1,88 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+
+using System;
+using System.Threading;
+
+class Test
+{
+ private Semaphore sem = null;
+ private const int numIterations = 1;
+ private const int numThreads = 10;
+ private int m_success;
+
+ static int Main()
+ {
+ Test t = new Test();
+ t.RunTest();
+ return t.CheckRet();
+
+ }
+
+ private void RunTest()
+ {
+ Semaphore s = new Semaphore(3,3);
+ sem = s;
+
+ Thread[] threads =new Thread[numThreads];
+
+ // Create the threads that will use the protected resource.
+ for(int i = 0; i < numThreads; i++)
+ {
+ threads[i] = new Thread(new ThreadStart(this.MyThreadProc));
+ threads[i].Name = String.Format("Thread{0}", i + 1);
+ threads[i].Start();
+ }
+
+ // The main thread exits, but the application continues to
+ // run until all foreground threads have exited.
+
+ for(int i =0; i< numThreads; i++) {
+ threads[i].Join();
+ }
+ }
+
+ private void MyThreadProc()
+ {
+ for(int i = 0; i < numIterations; i++)
+ {
+ UseResource();
+ }
+ }
+
+ private int CheckRet()
+ {
+ Console.WriteLine(m_success == numThreads ? "Test Passed":"Test Failed");
+ return (m_success == numThreads ? 100:-1);
+ }
+
+ private void Success()
+ {
+ Interlocked.Increment(ref m_success);
+ }
+
+ // This method represents a resource that must be synchronized
+ // so that only one thread at a time can enter.
+ private void UseResource()
+ {
+ // Wait until it is safe to enter.
+ sem.WaitOne();
+
+ Console.WriteLine("{0} has entered the protected area",
+ Thread.CurrentThread.Name);
+
+ // Place code to access non-reentrant resources here.
+
+ // Simulate some work.
+ Thread.Sleep(500);
+ Success();
+ Console.WriteLine("{0} is leaving the protected area\r\n",
+ Thread.CurrentThread.Name);
+
+ // Release the Mutex.
+ sem.Release();
+
+ }
+}
diff --git a/tests/src/baseservices/threading/semaphore/unit/semdemo.csproj b/tests/src/baseservices/threading/semaphore/unit/semdemo.csproj
new file mode 100644
index 0000000000..d6f681f6ae
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/unit/semdemo.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemDemo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/semaphore/unit/semtest.cs b/tests/src/baseservices/threading/semaphore/unit/semtest.cs
new file mode 100644
index 0000000000..599f864927
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/unit/semtest.cs
@@ -0,0 +1,190 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+
+using System;
+using System.Threading;
+
+class TestSemaphore
+{
+ const int intialCount = 10;
+ const int maximumCount = 10;
+
+ int successes;
+ int failures;
+ int expected;
+
+ public TestSemaphore()
+ {
+ successes = 0;
+ failures = 0;
+ expected = 8;
+ }
+
+ static int Main()
+ {
+ TestSemaphore myTest = new TestSemaphore();
+ myTest.NegativeTest();
+
+ myTest.FuncTest1();
+ myTest.FuncTest2();
+
+ myTest.FuncTest3();
+
+ return (myTest.CheckSuccess());
+ }
+
+ private int CheckSuccess()
+ {
+ if(successes == expected && failures == 0)
+ return 100;
+ return -1;
+ }
+
+ private void Failure(string message)
+ {
+ Console.WriteLine(message);
+ failures++;
+ }
+ private void Success()
+ {
+ successes++;
+ }
+
+ public void NegativeTest() {
+ try {
+ new Semaphore(-1, 0);
+ Failure("new Semaphore(-1, 0) Expected Exception is not thrown");
+ }
+ catch(ArgumentOutOfRangeException) {
+ Success();
+ }
+ catch {
+ Failure("UnExpected Exception thrown");
+ }
+
+ try {
+ new Semaphore(0, -1);
+ Failure("new Semaphore(0, -1) Expected Exception is not thrown");
+ }
+ catch(ArgumentOutOfRangeException) {
+ Success();
+ }
+ catch {
+ Failure("UnExpected Exception thrown");
+ }
+
+ try {
+ new Semaphore(1, 0);
+ Failure("new Semaphore(1, 0) Expected Exception is not thrown");
+ }
+ catch(ArgumentException) {
+ Success();
+ }
+ catch {
+ Failure("UnExpected Exception thrown");
+ }
+
+ }
+
+ public void FuncTest1() {
+ using (Semaphore sem = new Semaphore(intialCount, maximumCount))
+ {
+ sem.WaitOne();
+ int previousCount = sem.Release();
+ Console.WriteLine("Previous Count is {0}", previousCount);
+ if(previousCount != intialCount -1) {
+ Failure("Previous Count is not correct");
+ }
+ else
+ Success();
+
+ try {
+ sem.Release();
+ Failure("Expected Exception is not thrown");
+ }
+ catch(SemaphoreFullException) {
+ Success();
+ }
+ }
+
+ }
+
+ public void FuncTest2() {
+ using (Semaphore sem2 = new Semaphore(intialCount, maximumCount, "Semaphore_TESTSEM"))
+ {
+ bool createdNew;
+ using (Semaphore sem3 = new Semaphore(intialCount, maximumCount, "Semaphore_TESTSEM", out createdNew))
+ {
+ if( createdNew ) {
+ Failure("Error: we are not expecting a new semaphore here");
+ }
+ else
+ Success();
+ }
+
+ using (Semaphore sem4 = Semaphore.OpenExisting("Semaphore_TESTSEM"))
+ {
+ sem4.WaitOne();
+ sem4.WaitOne();
+ int previousCount = sem4.Release(2);
+ Console.WriteLine("Previous Count is {0}", previousCount);
+ if(previousCount != intialCount -2) {
+ Failure("Previous Count is not correct");
+ }
+ else
+ Success();
+ }
+ }
+ }
+
+ public void FuncTest3() {
+
+ Thread t = new Thread(new ThreadStart(Create));
+ Thread t2 = new Thread(new ThreadStart(Open));
+ __flag = false;
+ t.Start();
+ t2.Start();
+ t.Join();
+ t2.Join();
+
+
+ }
+ public bool __flag;
+
+ public void Create()
+ {
+ using (Semaphore sem = new Semaphore(intialCount, maximumCount, "Semaphore_TESTSEMOPEN"))
+ {
+ __flag = true;
+ while(__flag)
+ Thread.Sleep(0);
+ }
+ }
+
+ public void Open()
+ {
+ Semaphore sem4;
+ try{
+ while(!__flag)
+ Thread.Sleep(0);
+ using (sem4 = Semaphore.OpenExisting("Semaphore_TESTSEMOPEN"))
+ {
+ __flag = false;
+ Console.WriteLine("Opened on new thread");
+ Success();
+ sem4.WaitOne();
+ sem4.WaitOne();
+ }
+ }
+ catch(Exception e)
+ {
+ Failure(e.ToString());
+ }
+ finally
+ {
+ __flag = false;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/semaphore/unit/semtest.csproj b/tests/src/baseservices/threading/semaphore/unit/semtest.csproj
new file mode 100644
index 0000000000..0d53ea6f0f
--- /dev/null
+++ b/tests/src/baseservices/threading/semaphore/unit/semtest.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="SemTest.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/app.config b/tests/src/baseservices/threading/threadpool/bindhandle/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandle1.cs b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandle1.cs
new file mode 100644
index 0000000000..b0fe11adc9
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandle1.cs
@@ -0,0 +1,63 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.IO;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+/// <summary>
+/// Verifies passing an invalid handle (not overlapped) to BindHandle works as expected
+/// </summary>
+class BindHandle1
+{
+ public static int Main(string[] args)
+ {
+ return (new BindHandle1().RunTest());
+ }
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
+ public static extern IntPtr CreateFile(String FileName, uint Access, uint Share, int Atts, uint Dispo, uint Flags, int Template);
+
+
+ int RunTest()
+ {
+ try
+ {
+ try
+ {
+ using (SafeFileHandle sfh = new SafeFileHandle(CreateFile("test.txt", 0x40000000, 0, 0, 2, 0x40000000, 0), true))
+ {
+ if (ThreadPool.BindHandle(sfh))
+ {
+ Console.WriteLine("BindHandle call succeeded");
+ }
+ else
+ {
+ Console.WriteLine("Unexpected: BindHandle call failed");
+ return (98);
+ }
+
+ Console.WriteLine("Test passed");
+ return (100);
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Unexpected exception: {0}", ex);
+ return (98);
+ }
+ }
+ finally
+ {
+ if (File.Exists("test.txt"))
+ {
+ File.Delete("test.txt");
+ }
+ }
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandle1.csproj b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandle1.csproj
new file mode 100644
index 0000000000..81226abb4e
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandle1.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="BindHandle1.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid.cs b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid.cs
new file mode 100644
index 0000000000..a388d6c671
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using Microsoft.Win32.SafeHandles;
+
+class BindHandleInvalid
+{
+ public static int Main(string[] args)
+ {
+ return (new BindHandleInvalid().RunTest());
+ }
+
+ int RunTest()
+ {
+ SafeFileHandle sfh = new SafeFileHandle(IntPtr.Zero, false);
+
+ try
+ {
+ ThreadPool.BindHandle(sfh);
+ }
+ catch (Exception ex)
+ {
+ if (ex.ToString().IndexOf("0x80070006") != -1) // E_HANDLE, we can't access hresult
+ {
+ Console.WriteLine("Test passed");
+ return (100);
+ }
+ else
+ {
+ Console.WriteLine("Got wrong error: {0}", ex);
+ }
+ }
+ Console.WriteLine("Didn't get argument null exception");
+ return (99);
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid.csproj b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid.csproj
new file mode 100644
index 0000000000..9bd6454ebc
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="BindHandleInvalid.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid3.cs b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid3.cs
new file mode 100644
index 0000000000..519c843523
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid3.cs
@@ -0,0 +1,62 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.IO;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+/// <summary>
+/// Verifies passing an invalid handle (not overlapped) to BindHandle works as expected
+/// </summary>
+class BindHandleInvalid3
+{
+ public static int Main(string[] args)
+ {
+ return (new BindHandleInvalid3().RunTest());
+ }
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
+ public static extern IntPtr CreateFile(String FileName, uint Access, uint Share, int Atts, uint Dispo, uint Flags, int Template);
+
+
+ int RunTest()
+ {
+ try
+ {
+ try
+ {
+ using (SafeFileHandle sfh = new SafeFileHandle(CreateFile("test.txt", 0x40000000, 0, 0, 2, 0x80, 0), true))
+ {
+
+ ThreadPool.BindHandle(sfh);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (ex.ToString().IndexOf("0x80070057") != -1) // E_INVALIDARG, the handle isn't overlapped
+ {
+ Console.WriteLine("Test passed");
+ return (100);
+ }
+ else
+ {
+ Console.WriteLine("Got wrong error: {0}", ex);
+ }
+ }
+ }
+ finally
+ {
+ if (File.Exists("test.txt"))
+ {
+ File.Delete("test.txt");
+ }
+ }
+ Console.WriteLine("Didn't get argument null exception");
+ return (99);
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid3.csproj b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid3.csproj
new file mode 100644
index 0000000000..4a383bf62c
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid3.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="BindHandleInvalid3.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4.cs b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4.cs
new file mode 100644
index 0000000000..ebfde369f5
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4.cs
@@ -0,0 +1,57 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.IO;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+/// <summary>
+/// Verifies passing an invalid handle (not overlapped) to BindHandle works as expected
+/// </summary>
+class BindHandleInvalid3
+{
+ public static int Main(string[] args)
+ {
+ return (new BindHandleInvalid3().RunTest());
+ }
+
+ int RunTest()
+ {
+ try
+ {
+ try
+ {
+ using (FileStream fs1 = new FileStream("test.txt", FileMode.Create))
+ {
+ ThreadPool.BindHandle(fs1.SafeFileHandle);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (ex.ToString().IndexOf("0x80070057") != -1) // E_INVALIDARG, the handle isn't overlapped
+ {
+ Console.WriteLine("Test passed");
+ return (100);
+ }
+ else
+ {
+ Console.WriteLine("Got wrong error: {0}", ex);
+ }
+ }
+ }
+ finally
+ {
+ if (File.Exists("test.txt"))
+ {
+ File.Delete("test.txt");
+ }
+ }
+ Console.WriteLine("Didn't get argument null exception");
+ return (99);
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4.csproj b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4.csproj
new file mode 100644
index 0000000000..3ebde568e7
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="BindHandleInvalid4.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid5.cs b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid5.cs
new file mode 100644
index 0000000000..64f55a1750
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid5.cs
@@ -0,0 +1,63 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.IO;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+/// <summary>
+/// Verifies passing an invalid handle (not overlapped) to BindHandle works as expected
+/// </summary>
+class BindHandleInvalid3
+{
+ public static int Main(string[] args)
+ {
+ return (new BindHandleInvalid3().RunTest());
+ }
+
+ int RunTest()
+ {
+ try
+ {
+ try
+ {
+ using (FileStream fs1 = new FileStream("test.txt",
+ FileMode.Create,
+ FileAccess.ReadWrite,
+ FileShare.ReadWrite,
+ 0x10000,
+ true))
+ {
+
+ ThreadPool.BindHandle(fs1.SafeFileHandle);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (ex.ToString().IndexOf("0x80070057") != -1) // E_INVALIDARG, we've already bound the handle.
+ {
+ Console.WriteLine("Test passed");
+ return (100);
+ }
+ else
+ {
+ Console.WriteLine("Got wrong error: {0}", ex);
+ }
+ }
+ }
+ finally
+ {
+ if (File.Exists("test.txt"))
+ {
+ File.Delete("test.txt");
+ }
+ }
+ Console.WriteLine("Didn't get argument null exception");
+ return (99);
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid5.csproj b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid5.csproj
new file mode 100644
index 0000000000..03d7defff1
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid5.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="BindHandleInvalid5.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid6.cs b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid6.cs
new file mode 100644
index 0000000000..7700cc28c1
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid6.cs
@@ -0,0 +1,78 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.IO;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+/// <summary>
+/// Verifies passing an invalid handle (not overlapped) to BindHandle works as expected
+/// </summary>
+class BindHandle1
+{
+ public static int Main(string[] args)
+ {
+ return (new BindHandle1().RunTest());
+ }
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
+ public static extern IntPtr CreateFile(String FileName, uint Access, uint Share, int Atts, uint Dispo, uint Flags, int Template);
+
+ int RunTest()
+ {
+ try
+ {
+ try
+ {
+ using (SafeFileHandle sfh = new SafeFileHandle(CreateFile("test.txt", 0x40000000, 0, 0, 2, 0x40000000, 0), true))
+ {
+
+ try
+ {
+ if (ThreadPool.BindHandle(sfh))
+ {
+ Console.WriteLine("BindHandle call succeeded");
+ }
+ else
+ {
+ Console.WriteLine("Unexpected: BindHandle call failed");
+ return (98);
+ }
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Unexpected exception on 1st call: {0}", e);
+ return (92);
+ }
+
+ ThreadPool.BindHandle(sfh);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (ex.ToString().IndexOf("0x80070057") != -1) // E_INVALIDARG, we've already bound the handle.
+ {
+ Console.WriteLine("Test passed");
+ return (100);
+ }
+ else
+ {
+ Console.WriteLine("Got wrong error: {0}", ex);
+ }
+ }
+ }
+ finally
+ {
+ if (File.Exists("test.txt"))
+ {
+ File.Delete("test.txt");
+ }
+ }
+ return (99);
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid6.csproj b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid6.csproj
new file mode 100644
index 0000000000..08a3c41f95
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandleinvalid6.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="BindHandleInvalid6.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandlenull.cs b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandlenull.cs
new file mode 100644
index 0000000000..3eaee3d126
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandlenull.cs
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class BindHandleNull
+{
+ public static int Main(string[] args)
+ {
+ return (new BindHandleNull().RunTest());
+ }
+
+ int RunTest()
+ {
+ try
+ {
+ ThreadPool.BindHandle(null);
+ }
+ catch (ArgumentNullException)
+ {
+ Console.WriteLine("Test passed");
+ return (100);
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected: {0}", e);
+ return (98);
+ }
+ return (97);
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/bindhandlenull.csproj b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandlenull.csproj
new file mode 100644
index 0000000000..116a312c44
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/bindhandlenull.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="BindHandleNull.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/bindhandle/project.json b/tests/src/baseservices/threading/threadpool/bindhandle/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/bindhandle/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/ctorchk/app.config b/tests/src/baseservices/threading/threadpool/ctorchk/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/ctorchk/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/threadpool/ctorchk/ctorchk.cs b/tests/src/baseservices/threading/threadpool/ctorchk/ctorchk.cs
new file mode 100644
index 0000000000..957fe73470
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/ctorchk/ctorchk.cs
@@ -0,0 +1,30 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Reflection;
+
+class TestMonitor
+{
+ public static int Main()
+ {
+ // This will look for any private constructor.
+ // There shouldn't be one in Whidbey.
+ ConstructorInfo[] m = typeof(ThreadPool).GetConstructors(
+ BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public );
+ Console.WriteLine(m.Length);
+
+ if(m.Length > 0)
+ {
+ Console.WriteLine("Test FAILED!");
+ return 1;
+ }
+ else
+ {
+ Console.WriteLine("Test PASSED!");
+ return 100;
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/ctorchk/ctorchk.csproj b/tests/src/baseservices/threading/threadpool/ctorchk/ctorchk.csproj
new file mode 100644
index 0000000000..d30c021346
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/ctorchk/ctorchk.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="CtorChk.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/ctorchk/project.json b/tests/src/baseservices/threading/threadpool/ctorchk/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/ctorchk/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/unregister/app.config b/tests/src/baseservices/threading/threadpool/unregister/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/unregister/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/threadpool/unregister/project.json b/tests/src/baseservices/threading/threadpool/unregister/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/unregister/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/unregister/regression_749068.cs b/tests/src/baseservices/threading/threadpool/unregister/regression_749068.cs
new file mode 100644
index 0000000000..4f9deaab3b
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/unregister/regression_749068.cs
@@ -0,0 +1,137 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Threading;
+
+/************************
+ * Regression test for bug Bug 749068:WatsonCrash: coreclr.dll!Thread::DoAppropriateWaitWorker -- APPLICATION_HANG_BlockedOn_EventHandle c0000194
+ *
+ * Should be run with complus_GCStress=3
+ *
+ * During GC, no IO completion threads are created. So if there was no IO completion thread to begin with,
+ * there will be no threads monitoring the event which signals to schedule the corresponding callback,
+ * this blocks whatever code, which is waiting for the callback to finish or unregister it, indefinitely
+ *
+ ************************/
+namespace Prog
+{
+ class Callback
+ {
+ ManualResetEvent sessionNotification;
+ RegisteredWaitHandle sessionRegisteredWait;
+ public Callback()
+ {
+ this.sessionRegisteredWait = null;
+ this.sessionNotification = null;
+ }
+ public void ServiceCallbackOnPositionAvailable(Object state, bool timedOut)
+ {
+
+ if (this.sessionRegisteredWait == null)
+ {
+ this.sessionNotification.Reset();
+ this.sessionRegisteredWait.Unregister(null);
+
+ this.sessionRegisteredWait =
+ ThreadPool.RegisterWaitForSingleObject(this.sessionNotification,
+ ServiceCallbackOnPositionAvailable,
+ this, /* object state */
+ -1, /* INFINITE */
+ true /* ExecuteOnlyOnce */);
+
+ }
+ Console.WriteLine("callback running");
+
+ }
+ public void call()
+ {
+ if (this.sessionNotification != null)
+ this.sessionNotification.Set();
+ }
+ public void register()
+ {
+
+
+ this.sessionNotification = new ManualResetEvent(false);
+
+ this.sessionRegisteredWait = ThreadPool.RegisterWaitForSingleObject(
+ this.sessionNotification,
+ ServiceCallbackOnPositionAvailable,
+ this, /* object state */
+ -1, /* INFINITE */
+ true /* ExecuteOnlyOnce */);
+
+
+ }
+ public bool unregister()
+ {
+ ManualResetEvent callbackThreadComplete = new ManualResetEvent(false);
+ int timeToWait = 5000; //milliseconds
+ System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
+ sw.Start();
+ if (this.sessionRegisteredWait != null)
+ {
+ if (this.sessionRegisteredWait.Unregister(callbackThreadComplete))
+ {
+ Console.WriteLine("waiting on succesful unregister");
+ callbackThreadComplete.WaitOne(timeToWait);
+ }
+ }
+ this.sessionRegisteredWait = null;
+
+ long elapsed = sw.ElapsedMilliseconds;
+ Console.WriteLine("Elapsed: {0} millisec", elapsed);
+ if (elapsed >= timeToWait)
+ {
+ Console.WriteLine("Error. Callback was not signaled");
+ return false;
+ }
+ else
+ {
+ Console.WriteLine("Success");
+ return true;
+ }
+
+
+
+
+ }
+
+
+ }
+
+
+ class Program
+ {
+
+ static int Main(string[] args)
+ {
+ Callback obj = new Callback();
+
+ Console.WriteLine("start");
+ obj.register();
+
+ obj.call();
+ bool success = obj.unregister();
+
+ Console.WriteLine("end");
+ if (success)
+ {
+ Console.WriteLine("test passed");
+ return 100;
+ }
+ else
+ {
+ Console.WriteLine("test failed");
+ return 2;
+ }
+
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/threadpool/unregister/regression_749068.csproj b/tests/src/baseservices/threading/threadpool/unregister/regression_749068.csproj
new file mode 100644
index 0000000000..150313a6e4
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/unregister/regression_749068.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="Regression_749068.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/unregister/unregister01.cs b/tests/src/baseservices/threading/threadpool/unregister/unregister01.cs
new file mode 100644
index 0000000000..ad70603379
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/unregister/unregister01.cs
@@ -0,0 +1,64 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#region Using directives
+
+
+
+using System;
+
+using System.Collections.Generic;
+
+using System.Text;
+
+using System.Threading;
+
+
+
+#endregion
+
+
+
+namespace UnregisterWaitNativeBug
+{
+ class Program
+ {
+ public int ret = 0;
+ RegisteredWaitHandle[] regWait;
+ static int Main(string[] args)
+ {
+ Program p = new Program();
+ p.Run();
+ Console.WriteLine(100 == p.ret ? "Test Passed" : "Test Failed");
+ return p.ret;
+ }
+ public void Run()
+ {
+ int size = 100;
+ AutoResetEvent[] are = new AutoResetEvent[size];
+ regWait = new RegisteredWaitHandle[size];
+
+ for (int i = 0; i < size; i++)
+ {
+ are[i] = new AutoResetEvent(false);
+ regWait[i] = ThreadPool.RegisterWaitForSingleObject((WaitHandle)are[i], new WaitOrTimerCallback(TheCallBack), are[i], -1, false);
+ }
+
+ for (int i = 0; i < size; i++)
+ {
+ are[i].Set();
+ }
+ Thread.Sleep(1000);
+ for (int i = 0; i < size; i++)
+ {
+ regWait[i].Unregister(are[i]);
+ }
+ }
+ public void TheCallBack(object foo, bool state)
+ {
+ Interlocked.Increment(ref ret);
+ }
+ }
+}
+
diff --git a/tests/src/baseservices/threading/threadpool/unregister/unregister01.csproj b/tests/src/baseservices/threading/threadpool/unregister/unregister01.csproj
new file mode 100644
index 0000000000..245a8764dd
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/unregister/unregister01.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="Unregister01.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadpool/unregister/unregister03.cs b/tests/src/baseservices/threading/threadpool/unregister/unregister03.cs
new file mode 100644
index 0000000000..6454964f69
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/unregister/unregister03.cs
@@ -0,0 +1,65 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#region Using directives
+
+
+
+using System;
+
+using System.Collections.Generic;
+
+using System.Text;
+
+using System.Threading;
+
+
+
+#endregion
+
+
+
+namespace UnregisterWaitNativeBug
+{
+ class Program
+ {
+ public int ret = 0;
+ RegisteredWaitHandle[] regWait;
+ static int Main(string[] args)
+ {
+ Program p = new Program();
+ p.Run();
+ Console.WriteLine(100 == p.ret ? "Test Passed" : "Test Failed");
+ return p.ret;
+ }
+ public void Run()
+ {
+ int size = 100;
+ AutoResetEvent[] are = new AutoResetEvent[size];
+ regWait = new RegisteredWaitHandle[size];
+
+ for (int i = 0; i < size; i++)
+ {
+ are[i] = new AutoResetEvent(false);
+ regWait[i] = ThreadPool.RegisterWaitForSingleObject((WaitHandle)are[i], new WaitOrTimerCallback(TheCallBack), are[i], -1, false);
+ }
+
+ for (int i = 0; i < size; i++)
+ {
+ are[i].Set();
+ are[i] = null;
+ }
+ Thread.Sleep(1000);
+ for (int i = 0; i < size; i++)
+ {
+ regWait[i].Unregister(are[i]);
+ }
+ }
+ public void TheCallBack(object foo, bool state)
+ {
+ Interlocked.Increment(ref ret);
+ }
+ }
+}
+
diff --git a/tests/src/baseservices/threading/threadpool/unregister/unregister03.csproj b/tests/src/baseservices/threading/threadpool/unregister/unregister03.csproj
new file mode 100644
index 0000000000..8e06aa8d04
--- /dev/null
+++ b/tests/src/baseservices/threading/threadpool/unregister/unregister03.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="Unregister03.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/threadstatic/threadstatic07.cs b/tests/src/baseservices/threading/threadstatic/threadstatic07.cs
new file mode 100644
index 0000000000..600c6f6df4
--- /dev/null
+++ b/tests/src/baseservices/threading/threadstatic/threadstatic07.cs
@@ -0,0 +1,221 @@
+//Test is checking the ReserveSlot function
+// If someone screws up the function we will end up
+// setting values in the wrong slots and the totals will be wrong
+
+using System;
+using System.IO;
+using System.Threading;
+
+// Test Description:
+// Just basic heavy reading and writing from ThreadStatic members in normal threads and threadpools threads as well.
+// Ported from desktop test: BaseServices\Regression\V1\Threads\ThreadStatic\threadstatic1.cs
+
+public class Sensor
+{
+ [ThreadStatic]
+ static int A = 1;
+ [ThreadStatic]
+ static int B = 2;
+ [ThreadStatic]
+ static int C = 3;
+ [ThreadStatic]
+ static int D = 4;
+ [ThreadStatic]
+ static DateTime T = DateTime.Now;
+ [ThreadStatic]
+ static String S = "John Stockton";
+
+ static volatile int AA = -1;
+ static volatile int BB = -2;
+ static volatile int CC = -3;
+ static volatile int DD = -4;
+ static DateTime TT = DateTime.Now;
+ static String SS = "Karl Malone";
+ static volatile int Result = 100;
+
+ [ThreadStatic]
+ static int AAA = 5;
+ [ThreadStatic]
+ static int BBB = 6;
+ [ThreadStatic]
+ static int CCC = 7;
+ [ThreadStatic]
+ static int DDD = 8;
+ [ThreadStatic]
+ static DateTime TTT = DateTime.Now;
+ [ThreadStatic]
+ static String SSS = "Olden Polynice";
+
+ public static int Main(string[] args)
+ {
+ Console.WriteLine("Hello NBA Fans!!");
+ Console.WriteLine("ThreadStatic test 2: Various reading and writing of Threadstatic variables.");
+ Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", A, B, C, D, T, S);
+ Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", AA, BB, CC, DD, TT, SS);
+
+ ValueMess1();
+
+ StartThread();
+ if (Result != 100)
+ {
+ Console.WriteLine("Test Failed.");
+ }
+ else
+ {
+ Console.WriteLine("Test Succeeded.");
+ }
+
+ return Result;
+ }
+
+ public static void StartThread()
+ {
+ Thread SimulationThread;
+ Thread SimulationThread2;
+ Thread SimulationThread3;
+ Thread SimulationThread4;
+ Thread SimulationThread5;
+ Thread SimulationThread6;
+
+ ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFunc2), null);
+ ValueMess2();
+
+ ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFunc2), null);
+
+ ValueMess2();
+ SimulationThread = new Thread(new ThreadStart(ThreadFunc));
+ SimulationThread.Start();
+
+ ValueMess2();
+ SimulationThread2 = new Thread(new ThreadStart(ThreadFunc));
+ SimulationThread2.Start();
+
+ ValueMess2();
+ SimulationThread3 = new Thread(new ThreadStart(ThreadFunc));
+ SimulationThread3.Start();
+
+ ValueMess2();
+ SimulationThread4 = new Thread(new ThreadStart(ThreadFunc));
+ SimulationThread4.Start();
+
+ ValueMess2();
+ SimulationThread5 = new Thread(new ThreadStart(ThreadFunc));
+ SimulationThread5.Start();
+
+ ValueMess2();
+ SimulationThread6 = new Thread(new ThreadStart(ThreadFunc));
+ SimulationThread6.Start();
+ Thread.Sleep(500);
+ SimulationThread6.Join();
+
+ ValueMess1();
+ Console.WriteLine("Main A: {0}, {1}, {2}, {3}, {4}, {5}", A, B, C, D, T, S);
+ Console.WriteLine("Main AA: {0}, {1}, {2}, {3}, {4}, {5}", AA, BB, CC, DD, TT, SS);
+ Console.WriteLine("Main AAA: {0}, {1}, {2}, {3}, {4}, {5}", AAA, BBB, CCC, DDD, TTT, SSS);
+ int Y = Thread.CurrentThread.GetHashCode();
+ int X = (A ^ Y) | (B ^ Y) | (C ^ Y) |(D ^ Y)| (AAA ^ Y) | (BBB ^ Y) | (CCC ^ Y) |(DDD ^ Y);
+ Console.WriteLine("X: {0}, {1}", X, S);
+
+ if (X != 0)
+ {
+ Console.WriteLine("Something went wrong in thread: {0}", S);
+ Result = 700 + Y;
+ }
+ }
+
+ public static void ThreadFunc()
+ {
+ Console.WriteLine("ThreadStarted.. {0}", Thread.CurrentThread.GetHashCode().ToString());
+ Console.WriteLine("A: {0}, {1}, {2}, {3}, {4}, {5}", A, B, C, D, T, S);
+ Console.WriteLine("AA: {0}, {1}, {2}, {3}, {4}, {5}", AA, BB, CC, DD, TT, SS);
+ Console.WriteLine("AAA: {0}, {1}, {2}, {3}, {4}, {5}", AAA, BBB, CCC, DDD, TTT, SSS);
+
+ ValueMess1();
+
+ Console.WriteLine("A: {0}, {1}, {2}, {3}, {4}, {5}", A, B, C, D, T, S);
+ Console.WriteLine("AA: {0}, {1}, {2}, {3}, {4}, {5}", AA, BB, CC, DD, TT, SS);
+ Console.WriteLine("AAA: {0}, {1}, {2}, {3}, {4}, {5}", AAA, BBB, CCC, DDD, TTT, SSS);
+
+ int Y = Thread.CurrentThread.GetHashCode();
+ int X = (A ^ Y) | (B ^ Y) | (C ^ Y) |(D ^ Y)| (AAA ^ Y) | (BBB ^ Y) | (CCC ^ Y) |(DDD ^ Y);
+ Console.WriteLine("X: {0}, {1}", X, S);
+
+ if (X != 0)
+ {
+ Console.WriteLine("Something went wrong in thread: {0}", S);
+ Result = 700 + Y;
+ }
+ }
+
+ public static void ThreadFunc2(Object O)
+ {
+ Console.WriteLine("Threadpool Started.. {0}", Thread.CurrentThread.GetHashCode().ToString());
+ Console.WriteLine("TP A: {0}, {1}, {2}, {3}, {4}, {5}", A, B, C, D, T, S);
+ Console.WriteLine("TP AA: {0}, {1}, {2}, {3}, {4}, {5}", AA, BB, CC, DD, TT, SS);
+ Console.WriteLine("TP AAA: {0}, {1}, {2}, {3}, {4}, {5}", AAA, BBB, CCC, DDD, TTT, SSS);
+
+ ValueMess1();
+
+ Console.WriteLine("TP A: {0}, {1}, {2}, {3}, {4}, {5}", A, B, C, D, T, S);
+ Console.WriteLine("TP AA: {0}, {1}, {2}, {3}, {4}, {5}", AA, BB, CC, DD, TT, SS);
+ Console.WriteLine("TP AAA: {0}, {1}, {2}, {3}, {4}, {5}", AAA, BBB, CCC, DDD, TTT, SSS);
+
+ int Y = Thread.CurrentThread.GetHashCode();
+ int X = (A ^ Y) | (B ^ Y) | (C ^ Y) |(D ^ Y)| (AAA ^ Y) | (BBB ^ Y) | (CCC ^ Y) |(DDD ^ Y);
+ Console.WriteLine("X: {0}, {1}", X, S);
+
+ if (X != 0)
+ {
+ Console.WriteLine("Something went wrong in thread: {0}", S);
+ Result = 700 + Y;
+ }
+ }
+
+ public static void ValueMess1()
+ {
+ A = Thread.CurrentThread.GetHashCode();
+ B = Thread.CurrentThread.GetHashCode();
+ C = Thread.CurrentThread.GetHashCode();
+ D = Thread.CurrentThread.GetHashCode();
+ T = DateTime.Now;
+ S = Thread.CurrentThread.GetHashCode().ToString();
+
+ AA = Thread.CurrentThread.GetHashCode();
+ BB = Thread.CurrentThread.GetHashCode();
+ CC = Thread.CurrentThread.GetHashCode();
+ DD = Thread.CurrentThread.GetHashCode();
+ TT = DateTime.Now;
+ SS = Thread.CurrentThread.GetHashCode().ToString();
+
+ AAA = Thread.CurrentThread.GetHashCode();
+ BBB = Thread.CurrentThread.GetHashCode();
+ CCC = Thread.CurrentThread.GetHashCode();
+ DDD = Thread.CurrentThread.GetHashCode();
+ TTT = DateTime.Now;
+ SSS = Thread.CurrentThread.GetHashCode().ToString();
+ }
+
+ public static void ValueMess2()
+ {
+ A = -Thread.CurrentThread.GetHashCode();
+ B = -Thread.CurrentThread.GetHashCode();
+ C = -Thread.CurrentThread.GetHashCode();
+ D = -Thread.CurrentThread.GetHashCode();
+ T = DateTime.Now;
+ S = Thread.CurrentThread.GetHashCode().ToString();
+
+ AA = -Thread.CurrentThread.GetHashCode();
+ BB = -Thread.CurrentThread.GetHashCode();
+ CC = -Thread.CurrentThread.GetHashCode();
+ DD = -Thread.CurrentThread.GetHashCode();
+ TT = DateTime.Now;
+ SS = Thread.CurrentThread.GetHashCode().ToString();
+
+ AAA = -Thread.CurrentThread.GetHashCode();
+ BBB = -Thread.CurrentThread.GetHashCode();
+ CCC = -Thread.CurrentThread.GetHashCode();
+ DDD = -Thread.CurrentThread.GetHashCode();
+ TTT = DateTime.Now;
+ SSS = Thread.CurrentThread.GetHashCode().ToString();
+ }
+}
diff --git a/tests/src/baseservices/threading/threadstatic/threadstatic07.csproj b/tests/src/baseservices/threading/threadstatic/threadstatic07.csproj
new file mode 100644
index 0000000000..44db278c1a
--- /dev/null
+++ b/tests/src/baseservices/threading/threadstatic/threadstatic07.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="threadstatic07.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/app.config b/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/project.json b/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/threadabort.cs b/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/threadabort.cs
new file mode 100644
index 0000000000..c1c44dd2b1
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/threadabort.cs
@@ -0,0 +1,248 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Reflection;
+using System.Threading;
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+ private AutoResetEvent myARE;
+ int successes;
+ int failures;
+ int expected;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex(false, "myMutex");
+ myARE = new AutoResetEvent(true);
+ successes = 0;
+ failures = 0;
+ expected = 3;
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ wao.TestOne();
+ wao.TestTwo();
+ wao.TestThree();
+ return wao.CheckSuccess();
+ }
+
+ // This test ensures that an AbandonedMutexException is thrown when
+ // the thread is aborted and the mutex abandoned.
+ private void TestOne()
+ {
+ Console.WriteLine("MT: Test One");
+ // First thread abandon's the mutex by doing a thread.abort
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ // Second thread catches the exception
+ bool bRet = false;
+
+ myARE.Set();
+ Thread.Sleep(500);
+ ThreadAbort(t);
+ try
+ {
+ Console.WriteLine("MT: Wait on an abandoned mutex");
+ bRet = myMutex.WaitOne();
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ Console.WriteLine("MT PASS: AbandonedMutexException thrown!");
+ Success();
+ // Release the Mutex
+ myMutex.ReleaseMutex();
+ return;
+ }
+ catch(Exception e)
+ {
+ Failure("MT FAIL: Unexpected exception thrown: " +
+ e.ToString());
+ myMutex.ReleaseMutex();
+ return;
+ }
+ Failure("MT FAIL: Test did not throw AbandonedMutexException");
+ // Release the Mutex
+ myMutex.ReleaseMutex();
+ }
+
+ // This test ensures that releasing a Mutex in the catch works and
+ // does not throw an AbandonedMutexException
+ private void TestTwo()
+ {
+ Console.WriteLine("Test Two");
+ // First thread abandon's the mutex by doing a thread.abort
+ Thread t = new Thread(new ThreadStart(this.ReleaseInCatch));
+ t.Start();
+ // Second thread catches the exception
+ bool bRet = false;
+
+ myARE.Set();
+ Thread.Sleep(500);
+ ThreadAbort(t);
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bRet = myMutex.WaitOne();
+ }
+ catch(AbandonedMutexException)
+ {
+ // Not Expected
+ Failure("MT FAIL: Test threw an AbandonedMutexException!");
+ // Release the Mutex
+ myMutex.ReleaseMutex();
+ return;
+ }
+ catch(Exception e)
+ {
+ Failure("MT FAIL: Unexpected exception thrown: " +
+ e.ToString());
+ myMutex.ReleaseMutex();
+ return;
+ }
+ Console.WriteLine("MT PASS: No exception thrown!");
+ Success();
+ // Release the Mutex
+ myMutex.ReleaseMutex();
+ }
+
+ // This test ensures that releasing a Mutex in the finally works and
+ // does not throw an AbandonedMutexException
+ private void TestThree()
+ {
+ Console.WriteLine("Test Three");
+ // First thread abandon's the mutex by doing a thread.abort
+ Thread t = new Thread(new ThreadStart(this.ReleaseInFinally));
+ t.Start();
+ // Second thread catches the exception
+ bool bRet = false;
+
+ myARE.Set();
+ Thread.Sleep(500);
+ ThreadAbort(t);
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bRet = myMutex.WaitOne();
+ }
+ catch(AbandonedMutexException)
+ {
+ // Not Expected
+ Failure("MT FAIL: Test threw an AbandonedMutexException!");
+ // Release the Mutex
+ myMutex.ReleaseMutex();
+ return;
+ }
+ catch(Exception e)
+ {
+ Failure("MT FAIL: Unexpected exception thrown: " +
+ e.ToString());
+ myMutex.ReleaseMutex();
+ return;
+ }
+ Console.WriteLine("MT PASS: No exception thrown!");
+ Success();
+ // Release the Mutex
+ myMutex.ReleaseMutex();
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("ATM: Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("ATM: Waiting for signal");
+ // wait for signal to abort
+ myARE.WaitOne();
+ try
+ {
+ Thread.Sleep(10000);
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine(e);
+ Console.WriteLine("ATM: ThreadAbortException thrown");
+ // swallow exception to abandon mutex
+ myARE.Reset();
+ }
+ }
+
+ private void ReleaseInCatch()
+ {
+ Console.WriteLine("RIC: Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("RIC: Waiting for signal");
+ myARE.WaitOne();
+ try
+ {
+ Thread.Sleep(10000);
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine(e);
+ Console.WriteLine("RIC: ThreadAbortException thrown, releasing mutex");
+ myMutex.ReleaseMutex();
+ }
+ }
+
+ private void ReleaseInFinally()
+ {
+ Console.WriteLine("RIF: Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("RIF: Waiting for signal");
+ myARE.WaitOne();
+ try
+ {
+ Thread.Sleep(10000);
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine(e);
+ Console.WriteLine("RIF: ThreadAbortException thrown");
+ }
+ finally
+ {
+ myMutex.ReleaseMutex();
+ }
+ }
+
+ private int CheckSuccess()
+ {
+ if(successes == expected && failures == 0)
+ {
+ Console.WriteLine("**** All tests passed! ****");
+ return 100;
+ }
+ Console.WriteLine("There were one or more failures");
+ return -1;
+ }
+
+ private void Failure(string message)
+ {
+ Console.WriteLine(message);
+ failures++;
+ }
+
+ private void Success()
+ {
+ successes++;
+ }
+
+ private static void ThreadAbort(Thread thread)
+ {
+ MethodInfo abort = null;
+ foreach(MethodInfo m in thread.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
+ {
+ if (m.Name.Equals("AbortInternal") && m.GetParameters().Length == 0) abort = m;
+ }
+ if (abort == null) {
+ throw new Exception("Failed to get Thread.Abort method");
+ }
+ abort.Invoke(thread, new object[0]);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/threadabort.csproj b/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/threadabort.csproj
new file mode 100644
index 0000000000..df652b3fe0
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/abandonedmutexscenarios/threadabort.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="ThreadAbort.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/misc/app.config b/tests/src/baseservices/threading/waithandle/misc/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/misc/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/waithandle/misc/project.json b/tests/src/baseservices/threading/waithandle/misc/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/misc/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/misc/waithandledispose2.cs b/tests/src/baseservices/threading/waithandle/misc/waithandledispose2.cs
new file mode 100644
index 0000000000..c6dda93a8b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/misc/waithandledispose2.cs
@@ -0,0 +1,100 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+/// <summary>
+/// System.IDisposable.Dispose
+/// </summary>
+
+// Tests disposing of a WaitHandle-derived type
+// via the IDisposable interface.
+// This test is ok for Desktop, but
+// SL does not support Mutex
+public class WaitHandleDispose2
+{
+ #region Public Constants
+ public const int c_DEFAULT_WAIT_TIME = 1000; // 1 second
+ #endregion
+
+#region Public Methods
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ return retVal;
+ }
+
+ #region Positive Test Cases
+ public bool PosTest1()
+ {
+ bool retVal = false;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: Call Dispose");
+
+ try
+ {
+ // Mutex derives from WaitHandle,
+ // and normally you don't create a WaitHandle
+ WaitHandle handle = new Mutex();
+
+ // used to do a cast to IDisposable, but
+ // now WaitHandle implements the IDisposable
+ // interface directly
+ IDisposable disposable = handle as IDisposable;
+ disposable.Dispose();
+
+ // Dispose
+ //handle.Dispose();
+
+ // Do a waitone on the handle, should immediately throw
+ // ObjectDisposedException
+ handle.WaitOne(c_DEFAULT_WAIT_TIME);
+
+ // if we get here, it wasn't disposed of, error
+ TestLibrary.TestFramework.LogError("001", "handle.Dispose() did not dispose of the handle");
+ retVal = false;
+ }
+ catch (ObjectDisposedException)
+ {
+ // swallow it, this is where we wanted to go
+ retVal = true;
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+
+ return retVal;
+ }
+ #endregion
+ #endregion
+
+ [System.Security.SecurityCritical]
+ public static int Main()
+ {
+ WaitHandleDispose2 test = new WaitHandleDispose2();
+
+ TestLibrary.TestFramework.BeginTestCase("WaitHandleDispose2");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/misc/waithandledispose2.csproj b/tests/src/baseservices/threading/waithandle/misc/waithandledispose2.csproj
new file mode 100644
index 0000000000..a00142e65f
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/misc/waithandledispose2.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitHandleDispose2.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/misc/waithandlewaitone1.cs b/tests/src/baseservices/threading/waithandle/misc/waithandlewaitone1.cs
new file mode 100644
index 0000000000..c8815fff85
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/misc/waithandlewaitone1.cs
@@ -0,0 +1,292 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+/// <summary>
+/// WaitOne
+/// </summary>
+
+// Verifies that WaitOne can acquire a
+// mutex, that calling it while the mutex is held will
+// cause a thread to block, that if the mutex is
+// never released then WaitOne throws an
+// AbandonedMutexException, and that calling it on a
+// disposed-of mutex throws ObjectDisposedException
+// this test works for Orcas and Client, but Mutex
+// is not supported for Silverlight.
+public class WaitHandleWaitOne1
+{
+ #region Private Fields
+ private const int c_DEFAULT_SLEEP_TIME = 5000; // 1 second
+
+ private WaitHandle m_Handle = null;
+ #endregion
+
+ #region Public Methods
+ public bool RunTests()
+ {
+ bool retVal = true;
+
+ TestLibrary.TestFramework.LogInformation("[Positive]");
+ retVal = PosTest1() && retVal;
+
+ TestLibrary.TestFramework.LogInformation("[Negative]");
+ retVal = NegTest1() && retVal;
+ retVal = NegTest2() && retVal;
+
+ return retVal;
+ }
+
+ #region Positive Test Cases
+ // this one tests that a WaitOne will wait on a Mutex
+ // and then grab it when it is free
+ public bool PosTest1()
+ {
+ bool retVal = false;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("PosTest1: WaitOne returns true when current instance receives a signal");
+
+ // m_Handle is of type WaitHandle
+ // Mutex is a subclass of WaitHandle
+ using(m_Handle = new Mutex())
+ {
+ try
+ {
+ // Spin up a thread. SignalMutex grabs
+ // the Mutex, then goes to sleep for 5 seconds. It
+ // only releases the mutex after sleeping for those
+ // 5 seconds
+ thread = new Thread(new ThreadStart(SignalMutex));
+ // Start it
+ thread.Start();
+ // Then put this calling thread to sleep
+ // for one second so that it doesn't beat the spawned
+ // thread to the mutex
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
+ // Now, the spawned thread should already
+ // have the mutex and be sleeping on it for several
+ // seconds. try to grab the mutex now. We should
+ // simply block until the other thread releases it,
+ // then we should get it.
+ // Net result, we should get true back from WaitOne
+ if (m_Handle.WaitOne() != true)
+ {
+ TestLibrary.TestFramework.LogError("001", "WaitOne returns false when current instance receives a signal.");
+ retVal = false;
+
+ }
+ else
+ {
+ // got the mutex ok
+ retVal = true;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ // Wait for the thread to terminate
+ if (null != thread)
+ {
+ // Wait on that thread
+ thread.Join();
+ }
+ }
+ }
+
+ return retVal;
+ }
+ #endregion
+
+ #region Negative Test Cases
+ // this one just tests that a WaitOne will receive
+ // a AbandonedMutexException
+ public bool NegTest1()
+ {
+ bool retVal = false;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("NegTest1: AbandonedMutexException should be thrown if a thread exited without releasing a mutex");
+
+ // m_Handle is of type WaitHandle
+ // Mutex is a subclass of WaitHandle
+ using(m_Handle = new Mutex())
+ {
+ try
+ {
+ // Spin up a thread. SignalMutex grabs
+ // the Mutex, then goes to sleep for 5 seconds.
+ thread = new Thread(new ThreadStart(NeverReleaseMutex));
+ // Start it
+ thread.Start();
+ // Then put this calling thread to sleep
+ // for just over one second so that it doesn't beat
+ // the spawned thread to the mutex
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 3); // To avoid race
+ // Now, the spawned thread should already
+ // have the mutex and be sleeping on it forever.
+ // try to grab the mutex now. We should simply block until
+ // the other thread releases it, which is never. When that
+ // thread returns from its method, an AbandonedMutexException
+ // should be thrown instead
+ m_Handle.WaitOne();
+
+ // We should not get here
+ TestLibrary.TestFramework.LogError("101", "AbandonedMutexException is not thrown if a thread exited without releasing a mutex");
+ retVal = false;
+ }
+ catch (AbandonedMutexException)
+ {
+ // Swallow it, this is where we want
+ // the test to go
+ retVal = true;
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ if (null != thread)
+ {
+ // The spawned thread is still running.
+ // Join on it until it is done
+ thread.Join();
+ }
+ }
+ }
+
+ return retVal;
+ }
+
+ // this one just tests that WaitOne will receive an
+ // ObjectDisposedException if the Mutex is disposed of
+ // by the spawned thread while WaitOne is waiting on it
+ public bool NegTest2()
+ {
+ bool retVal = false;
+ Thread thread = null;
+
+ TestLibrary.TestFramework.BeginScenario("NegTest2: ObjectDisposedException should be thrown if current instance has already been disposed");
+
+ try
+ {
+ // m_Handle is of type WaitHandle
+ // Mutex is a subclass of WaitHandle
+ m_Handle = new Mutex();
+
+ // Spin up a thread. DisposeMutex
+ // simply tries to dispose of the mutex.
+ thread = new Thread(new ThreadStart(DisposeMutex));
+ // Start it
+ thread.Start();
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ // Now, the spawned thread should have
+ // had plenty of time to dispose of the mutex
+ // Calling WaitOne at this point should result
+ // in an ObjectDisposedException being thrown
+ m_Handle.WaitOne();
+
+ // We should not get here
+ TestLibrary.TestFramework.LogError("103", "ObjectDisposedException is not thrown if current instance has already been disposed");
+ retVal = false;
+ }
+ catch (ObjectDisposedException)
+ {
+ // Swallow it, this is where we want
+ // the test to go
+ retVal = true;
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e);
+ TestLibrary.TestFramework.LogInformation(e.StackTrace);
+ retVal = false;
+ }
+ finally
+ {
+ if (null != thread)
+ {
+ // Wait for the spawned thread to finish
+ // cleaning up
+ thread.Join();
+ }
+
+ if (null != m_Handle)
+ {
+ // spawned thread was unable to dispose of it
+ ((IDisposable)m_Handle).Dispose();
+ }
+ }
+
+ return retVal;
+ }
+ #endregion
+ #endregion
+
+ public static int Main()
+ {
+ WaitHandleWaitOne1 test = new WaitHandleWaitOne1();
+
+ TestLibrary.TestFramework.BeginTestCase("WaitHandleWaitOne1");
+
+ if (test.RunTests())
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("PASS");
+ return 100;
+ }
+ else
+ {
+ TestLibrary.TestFramework.EndTestCase();
+ TestLibrary.TestFramework.LogInformation("FAIL");
+ return 0;
+ }
+ }
+
+ #region Private Methods
+ private void SignalMutex()
+ {
+ // Request ownership of the mutex.
+ // You can use the WaitHandle.WaitOne
+ // method to request ownership of a mutex. Block
+ // until m_Handle receives a signal
+ m_Handle.WaitOne();
+ // Put this thread to sleep
+ // for 5 seconds
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ // Then release the mutex
+ (m_Handle as Mutex).ReleaseMutex();
+ }
+
+ private void NeverReleaseMutex()
+ {
+ // Request ownership of the mutex.
+ // You can use the WaitHandle.WaitOne
+ // method to request ownership of a mutex. Block
+ // until m_Handle receives a signal
+ m_Handle.WaitOne();
+ // Put this thread to sleep
+ // for 5 seconds
+ Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+ // And we never release
+ // the mutex
+ }
+
+ private void DisposeMutex()
+ {
+ ((IDisposable)m_Handle).Dispose();
+ }
+ #endregion
+}
diff --git a/tests/src/baseservices/threading/waithandle/misc/waithandlewaitone1.csproj b/tests/src/baseservices/threading/waithandle/misc/waithandlewaitone1.csproj
new file mode 100644
index 0000000000..c86823aa9d
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/misc/waithandlewaitone1.csproj
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitHandleWaitOne1.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(SourceDir)\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj">
+ <Project>{8ffe99c0-22f8-4462-b839-970eac1b3472}</Project>
+ <Name>coreclr</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/app.config b/tests/src/baseservices/threading/waithandle/waitall/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/waithandle/waitall/emptyarray.cs b/tests/src/baseservices/threading/waithandle/waitall/emptyarray.cs
new file mode 100644
index 0000000000..47f6bdfa85
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/emptyarray.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+//Regression for DevDiv Bugs 1142
+class Duplicates
+{
+ static int Main()
+ {
+ int retCode = 99;
+
+ WaitHandle[] waitHandles = {};
+
+ // Can't catch exception in v2.0. Should be fixed in Post-Orcas. VSWhidbey 543816
+ try
+ {
+ Console.WriteLine("Before WaitAll");
+ WaitHandle.WaitAll(waitHandles, 5000);
+ Console.WriteLine("After WaitAll");
+ }
+ catch (ArgumentException)
+ {
+ retCode = 100;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("WaitAll threw unexpected Exception.");
+ Console.WriteLine("WaitAll: {0}", ex);
+ retCode = 98;
+ }
+
+ if (retCode ==100)
+ Console.WriteLine("Test Passed");
+ else
+ Console.WriteLine("Test Failed");
+
+ return retCode;
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/nullarray.cs b/tests/src/baseservices/threading/waithandle/waitall/nullarray.cs
new file mode 100644
index 0000000000..cdc17e4a23
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/nullarray.cs
@@ -0,0 +1,52 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+//Regression for DevDiv Bugs 1142
+class Duplicates
+{
+ static int Main()
+ {
+ int retCode = 99;
+
+ // Console.WriteLine(Thread.CurrentThread.GetApartmentState());
+
+ // Not supported (CoreCLR GitHub issue #2999)
+ // AppDomain.CurrentDomain.UnhandledException += Unhandled;
+
+ WaitHandle[] waitHandles = null;
+
+ // Can't catch exception in v2.0. Should be fixed in Post-Orcas. VSWhidbey 543816
+ try
+ {
+ Console.WriteLine("Before WaitAll");
+ WaitHandle.WaitAll(waitHandles, 5000);//, false);
+ Console.WriteLine("After WaitAll");
+ }
+ catch (ArgumentNullException)
+ {
+ retCode = 100;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("WaitAll threw unexpected Exception.");
+ Console.WriteLine("WaitAll: {0}", ex);
+ retCode = 98;
+ }
+
+ if (retCode ==100)
+ Console.WriteLine("Test Passed");
+ else
+ Console.WriteLine("Test Failed");
+
+ return retCode;
+ }
+
+ // private static void Unhandled(object sender, UnhandledExceptionEventArgs args)
+ // {
+ // Exception e = (Exception) args.ExceptionObject;
+ // Console.WriteLine("Unhandled reports: {0}", e);
+ // }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/nullarraymember.cs b/tests/src/baseservices/threading/waithandle/waitall/nullarraymember.cs
new file mode 100644
index 0000000000..61b1e9e9f2
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/nullarraymember.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class Duplicates
+{
+ static int Main()
+ {
+ int retCode = 99;
+
+ WaitHandle[] waitHandles = { new Mutex(), new Mutex(), null, new Mutex() };
+
+ // Can't catch exception in v2.0. Should be fixed in Post-Orcas. VSWhidbey 543816
+ try
+ {
+ Console.WriteLine("Before WaitAll");
+ WaitHandle.WaitAll(waitHandles, 5000);
+ Console.WriteLine("After WaitAll");
+ }
+ catch (ArgumentNullException)
+ {
+ retCode = 100;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("WaitAll threw unexpected Exception.");
+ Console.WriteLine("WaitAll: {0}", ex);
+ retCode = 98;
+ }
+
+ if (retCode ==100)
+ Console.WriteLine("Test Passed");
+ else
+ Console.WriteLine("Test Failed");
+
+ return retCode;
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/nullarraymember.csproj b/tests/src/baseservices/threading/waithandle/waitall/nullarraymember.csproj
new file mode 100644
index 0000000000..b8267c3c4d
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/nullarraymember.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="NullArrayMember.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/project.json b/tests/src/baseservices/threading/waithandle/waitall/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallemptyarray.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallemptyarray.csproj
new file mode 100644
index 0000000000..9621e3b064
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallemptyarray.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="EmptyArray.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex1.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex1.cs
new file mode 100644
index 0000000000..2adb4efefe
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex1.cs
@@ -0,0 +1,60 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMutex = new Mutex(false, Common.GetUniqueName());
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Testing Mutex and non-Mutex, " +
+ "not signaling the other element");
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(
+ new WaitHandle[]{myMutex,
+ new ManualResetEvent(false)}, 5000);
+ // Expected timeout and NOT throw exception
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("Holding the Mutex");
+ // Not calling ReleaseMutex() so the Mutex becomes abandoned
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex1.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex1.csproj
new file mode 100644
index 0000000000..01d5af5623
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex1.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx1.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex10.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex10.cs
new file mode 100644
index 0000000000..32a61f4fe0
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex10.cs
@@ -0,0 +1,103 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ WaitHandle[] wh;
+ ManualResetEvent myMRE;
+
+ public WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAllEx10 /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iNumElements, int iPos)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon during a wait, signaling others - " +
+ iNumElements + ", " + iPos);
+ CreateOneMutexArray(iNumElements, iPos);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexesWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh, 10000);
+ Console.WriteLine("AbandonedMutexException was not thrown!");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexesWait()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ else
+ ((ManualResetEvent)w).Set();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateOneMutexArray(int numElements, int iPos)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ if(i == iPos)
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ else
+ wh[i] = new ManualResetEvent(false);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex10.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex10.csproj
new file mode 100644
index 0000000000..ecba7ecde0
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex10.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:64 /pos:63</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx10.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex10a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex10a.cs
new file mode 100644
index 0000000000..98f98261a4
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex10a.cs
@@ -0,0 +1,103 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ WaitHandle[] wh;
+ ManualResetEvent myMRE;
+
+ public WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAllEx10 /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iNumElements, int iPos)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon during a wait, signaling others - " +
+ iNumElements + ", " + iPos);
+ CreateOneMutexArray(iNumElements, iPos);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexesWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh);
+ Console.WriteLine("AbandonedMutexException was not thrown!");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexesWait()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ else
+ ((ManualResetEvent)w).Set();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateOneMutexArray(int numElements, int iPos)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ if(i == iPos)
+ wh[i] = new Mutex();
+ else
+ wh[i] = new ManualResetEvent(false);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex10a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex10a.csproj
new file mode 100644
index 0000000000..e1cf0fc201
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex10a.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:64 /pos:0</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx10a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex11.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex11.cs
new file mode 100644
index 0000000000..cb2f8d72ca
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex11.cs
@@ -0,0 +1,70 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon before a wait");
+ CreateMutexArray(64);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonMutexWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh, 10000);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexWait()
+ {
+ wh[63].WaitOne();
+ myMRE.Set();
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex11.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex11.csproj
new file mode 100644
index 0000000000..51bce3e95b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex11.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx11.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex11a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex11a.cs
new file mode 100644
index 0000000000..d98e0265d0
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex11a.cs
@@ -0,0 +1,70 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon before a wait");
+ CreateMutexArray(64);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonMutexWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexWait()
+ {
+ wh[63].WaitOne();
+ myMRE.Set();
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex();
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex11a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex11a.csproj
new file mode 100644
index 0000000000..041c249207
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex11a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx11a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex1a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex1a.cs
new file mode 100644
index 0000000000..3c63d0bb51
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex1a.cs
@@ -0,0 +1,60 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMutex = new Mutex();
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Testing Mutex and non-Mutex, " +
+ "not signaling the other element");
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(
+ new WaitHandle[]{myMutex,
+ new ManualResetEvent(false)}, 5000);
+ // Expected timeout and NOT throw exception
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("Holding the Mutex");
+ // Not calling ReleaseMutex() so the Mutex becomes abandoned
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex1a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex1a.csproj
new file mode 100644
index 0000000000..264f35cbb7
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex1a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx1a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex2.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex2.cs
new file mode 100644
index 0000000000..0970739515
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex2.cs
@@ -0,0 +1,66 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMutex = new Mutex(false, Common.GetUniqueName());
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Testing Mutex and non-Mutex, " +
+ "and signaling the other element");
+ Thread t = new Thread(new ThreadStart(this.AbandonAndSet));
+ t.Start();
+ myMRE.WaitOne();
+ bool bRet = false;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bRet = WaitHandle.WaitAll(
+ new WaitHandle[]{myMutex, myMRE}, 5000);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAndSet()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("Holding the Mutex");
+ // Signaling the Event
+ myMRE.Set();
+ // Not calling ReleaseMutex() so the Mutex becomes abandoned
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex2.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex2.csproj
new file mode 100644
index 0000000000..89283a75c6
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex2.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx2.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex2a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex2a.cs
new file mode 100644
index 0000000000..fdddeb7811
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex2a.cs
@@ -0,0 +1,66 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMutex = new Mutex();
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Testing Mutex and non-Mutex, " +
+ "and signaling the other element");
+ Thread t = new Thread(new ThreadStart(this.AbandonAndSet));
+ t.Start();
+ myMRE.WaitOne();
+ bool bRet = false;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bRet = WaitHandle.WaitAll(
+ new WaitHandle[]{myMutex, myMRE});
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAndSet()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("Holding the Mutex");
+ // Signaling the Event
+ myMRE.Set();
+ // Not calling ReleaseMutex() so the Mutex becomes abandoned
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex2a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex2a.csproj
new file mode 100644
index 0000000000..cbd1517742
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex2a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx2a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex3.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex3.cs
new file mode 100644
index 0000000000..da2678f7e3
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex3.cs
@@ -0,0 +1,97 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning more than one mutex mix " +
+ "with other WaitHandles, signaling other elements");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexes));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh, 10000);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexes()
+ {
+ Mutex m = new Mutex();
+ AutoResetEvent are = new AutoResetEvent(false);
+
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == myMRE.GetType())
+ ((ManualResetEvent)w).Set();
+ if(w.GetType() == are.GetType())
+ ((AutoResetEvent)w).Set();
+ }
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%4)
+ {
+ case 0:
+ wh[i] = new AutoResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 2:
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ break;
+ case 3:
+ wh[i] = new Semaphore(5,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex3.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex3.csproj
new file mode 100644
index 0000000000..76a77b7dc8
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex3.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx3.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex3a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex3a.cs
new file mode 100644
index 0000000000..acd4753e6b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex3a.cs
@@ -0,0 +1,97 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning more than one mutex mix " +
+ "with other WaitHandles, signaling other elements");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexes));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexes()
+ {
+ Mutex m = new Mutex();
+ AutoResetEvent are = new AutoResetEvent(false);
+
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == myMRE.GetType())
+ ((ManualResetEvent)w).Set();
+ if(w.GetType() == are.GetType())
+ ((AutoResetEvent)w).Set();
+ }
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%4)
+ {
+ case 0:
+ wh[i] = new AutoResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 2:
+ wh[i] = new Mutex();
+ break;
+ case 3:
+ wh[i] = new Semaphore(5,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex3a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex3a.csproj
new file mode 100644
index 0000000000..6f3d01a944
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex3a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx3a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex4.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex4.cs
new file mode 100644
index 0000000000..666b1cefa3
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex4.cs
@@ -0,0 +1,87 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning only one Mutex " +
+ "in array with other WaitHandles");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonOne));
+ t.Start();
+ myMRE.WaitOne();
+ bool bRet = false;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bRet = WaitHandle.WaitAll(wh, 5000);
+ // Expected timeout and no exception thrown
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonOne()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ {
+ w.WaitOne();
+ break;
+ }
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%4)
+ {
+ case 0:
+ wh[i] = new AutoResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 2:
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ break;
+ case 3:
+ wh[i] = new Semaphore(5,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex4.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex4.csproj
new file mode 100644
index 0000000000..e52727eb33
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex4.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx4.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex4a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex4a.cs
new file mode 100644
index 0000000000..5b98e4476e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex4a.cs
@@ -0,0 +1,87 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning only one Mutex " +
+ "in array with other WaitHandles");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonOne));
+ t.Start();
+ myMRE.WaitOne();
+ bool bRet = false;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bRet = WaitHandle.WaitAll(wh, 5000);
+ // Expected timeout and no exception thrown
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonOne()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ {
+ w.WaitOne();
+ break;
+ }
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%4)
+ {
+ case 0:
+ wh[i] = new AutoResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new ManualResetEvent(true);
+ break;
+ case 2:
+ wh[i] = new Mutex();
+ break;
+ case 3:
+ wh[i] = new Semaphore(5,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex4a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex4a.csproj
new file mode 100644
index 0000000000..92294da500
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex4a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx4a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex5.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex5.cs
new file mode 100644
index 0000000000..e3232cc73d
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex5.cs
@@ -0,0 +1,89 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning only one Mutex in array " +
+ "with other WaitHandles, signaling other mutexes");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonOneAndRelease));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh, 5000);
+ // Expected timeout and no exception thrown
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonOneAndRelease()
+ {
+ Mutex m = new Mutex();
+ bool bSet = false;
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ {
+ w.WaitOne();
+ myMRE.Set();
+ if(bSet)
+ ((Mutex)w).ReleaseMutex();
+ bSet = true;
+ }
+ }
+ Thread.Sleep(1000);
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%4)
+ {
+ case 0:
+ wh[i] = new AutoResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 2:
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ break;
+ case 3:
+ wh[i] = new Semaphore(5,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex5.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex5.csproj
new file mode 100644
index 0000000000..40719800b7
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex5.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx5.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex5a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex5a.cs
new file mode 100644
index 0000000000..a59ebbb2ce
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex5a.cs
@@ -0,0 +1,89 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning only one Mutex in array " +
+ "with other WaitHandles, signaling other mutexes");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonOneAndRelease));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh, 5000);
+ // Expected timeout and no exception thrown
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonOneAndRelease()
+ {
+ Mutex m = new Mutex();
+ bool bSet = false;
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ {
+ w.WaitOne();
+ myMRE.Set();
+ if(bSet)
+ ((Mutex)w).ReleaseMutex();
+ bSet = true;
+ }
+ }
+ Thread.Sleep(1000);
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%4)
+ {
+ case 0:
+ wh[i] = new AutoResetEvent(true);
+ break;
+ case 1:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 2:
+ wh[i] = new Mutex();
+ break;
+ case 3:
+ wh[i] = new Semaphore(5,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex5a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex5a.csproj
new file mode 100644
index 0000000000..49e570c64a
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex5a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx5a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex6.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex6.cs
new file mode 100644
index 0000000000..450e101e16
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex6.cs
@@ -0,0 +1,94 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAllEx6 /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iArraySize, int iPosToAbandon)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon a particular mutex - " + iArraySize + ", " +
+ iPosToAbandon);
+ CreateMutexArray(iArraySize);
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(iPosToAbandon);
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh, 5000);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex6.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex6.csproj
new file mode 100644
index 0000000000..e5680a6af2
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex6.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:2 /pos:0</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx6.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex6a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex6a.cs
new file mode 100644
index 0000000000..a5573ad712
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex6a.cs
@@ -0,0 +1,94 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAllEx6a /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iArraySize, int iPosToAbandon)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon a particular mutex - " + iArraySize + ", " +
+ iPosToAbandon);
+ CreateMutexArray(iArraySize);
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(iPosToAbandon);
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex();
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex6a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex6a.csproj
new file mode 100644
index 0000000000..1431e10e56
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex6a.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:64 /pos:30</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx6a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex7.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex7.cs
new file mode 100644
index 0000000000..8e216d9a3b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex7.cs
@@ -0,0 +1,76 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon all mutexes in array");
+ CreateMutexArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexes));
+ t.Start();
+ myMRE.WaitOne();
+ bool bRet = false;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bRet = WaitHandle.WaitAll(wh, 5000);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexes()
+ {
+ Mutex m = new Mutex();
+ AutoResetEvent are = new AutoResetEvent(false);
+
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex7.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex7.csproj
new file mode 100644
index 0000000000..f3efe3041e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex7.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx7.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex7a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex7a.cs
new file mode 100644
index 0000000000..69bcd965d1
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex7a.cs
@@ -0,0 +1,76 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon all mutexes in array");
+ CreateMutexArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexes));
+ t.Start();
+ myMRE.WaitOne();
+ bool bRet = false;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bRet = WaitHandle.WaitAll(wh);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexes()
+ {
+ Mutex m = new Mutex();
+ AutoResetEvent are = new AutoResetEvent(false);
+
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex();
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex7a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex7a.csproj
new file mode 100644
index 0000000000..fd0835cba2
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex7a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx7a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex8.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex8.cs
new file mode 100644
index 0000000000..2d796e61bf
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex8.cs
@@ -0,0 +1,76 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon same named mutex");
+ // Create array with the same name
+ string sName = Common.GetUniqueName();
+ wh = new Mutex[2];
+ wh[0] = new Mutex(false, sName);
+ wh[1] = new Mutex(false, sName);
+
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(0);
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh, 10000);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(ArgumentException)
+ {
+ // bug #237497 - ArgumentException is thrown instead of
+ // an AbandonedMutexException.
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex8.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex8.csproj
new file mode 100644
index 0000000000..a9bdcf4c67
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex8.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx8.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex8a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex8a.cs
new file mode 100644
index 0000000000..99b5234d9f
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex8a.cs
@@ -0,0 +1,76 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ private WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ private WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon same named mutex");
+ // Create array with the same name
+ string sName = Common.GetUniqueName();
+ wh = new Mutex[2];
+ wh[0] = new Mutex(false, sName);
+ wh[1] = new Mutex(false, sName);
+
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(0);
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh);
+ Console.WriteLine("WaitAll did not throw an " +
+ "exception, bRet = " + bRet);
+ }
+ catch(ArgumentException)
+ {
+ // bug #237497 - ArgumentException is thrown instead of
+ // an AbandonedMutexException.
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex();
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex8a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex8a.csproj
new file mode 100644
index 0000000000..d928b2cc5e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex8a.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx8a.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex9.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex9.cs
new file mode 100644
index 0000000000..f8ea18511f
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex9.cs
@@ -0,0 +1,100 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ WaitHandle[] wh;
+ ManualResetEvent myMRE;
+
+ public WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAllEx9 /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iNumElements, int iPos)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon during a wait - " + iNumElements + ", " +
+ iPos);
+ CreateOneMutexArray(iNumElements, iPos);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexesWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh, 5000);
+ // Expected timeout and pass
+ if(bRet)
+ Console.WriteLine("No exception thrown!");
+ else
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexesWait()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateOneMutexArray(int numElements, int iPos)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ if(i == iPos)
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ else
+ wh[i] = new ManualResetEvent(false);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex9.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex9.csproj
new file mode 100644
index 0000000000..3ded5895c2
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex9.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:64 /pos:63</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx9.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex9a.cs b/tests/src/baseservices/threading/waithandle/waitall/waitallex9a.cs
new file mode 100644
index 0000000000..37b2484656
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex9a.cs
@@ -0,0 +1,100 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAllEx
+{
+ WaitHandle[] wh;
+ ManualResetEvent myMRE;
+
+ public WaitAllEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAllEx9a /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAllEx wae = new WaitAllEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iNumElements, int iPos)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon during a wait - " + iNumElements + ", " +
+ iPos);
+ CreateOneMutexArray(iNumElements, iPos);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexesWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ bool bRet = WaitHandle.WaitAll(wh, 5000);
+ // Expected timeout and pass
+ if(bRet)
+ Console.WriteLine("No exception thrown!");
+ else
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexesWait()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateOneMutexArray(int numElements, int iPos)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ if(i == iPos)
+ wh[i] = new Mutex();
+ else
+ wh[i] = new ManualResetEvent(false);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallex9a.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallex9a.csproj
new file mode 100644
index 0000000000..2f02bc9b42
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallex9a.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:64 /pos:0</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAllEx9a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitall/waitallnullarray.csproj b/tests/src/baseservices/threading/waithandle/waitall/waitallnullarray.csproj
new file mode 100644
index 0000000000..2f0429d6ae
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitall/waitallnullarray.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="NullArray.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/app.config b/tests/src/baseservices/threading/waithandle/waitany/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/waithandle/waitany/emptyarray.cs b/tests/src/baseservices/threading/waithandle/waitany/emptyarray.cs
new file mode 100644
index 0000000000..ef15894d79
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/emptyarray.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+//Regression for DevDiv Bugs 1142
+class Duplicates
+{
+ static int Main()
+ {
+ int retCode = 99;
+
+ WaitHandle[] waitHandles = {};
+
+ // Can't catch exception in v2.0. Should be fixed in Post-Orcas. VSWhidbey 543816
+ try
+ {
+ Console.WriteLine("Before WaitAny");
+ WaitHandle.WaitAny(waitHandles, 5000);
+ Console.WriteLine("After WaitAny");
+ }
+ catch (ArgumentException)
+ {
+ retCode = 100;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("WaitAny threw unexpected Exception.");
+ Console.WriteLine("WaitAny: {0}", ex);
+ retCode = 98;
+ }
+
+ if (retCode ==100)
+ Console.WriteLine("Test Passed");
+ else
+ Console.WriteLine("Test Failed");
+
+ return retCode;
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/nullarray.cs b/tests/src/baseservices/threading/waithandle/waitany/nullarray.cs
new file mode 100644
index 0000000000..7d4cb18d5a
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/nullarray.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+//Regression for DevDiv Bugs 1142
+class Duplicates
+{
+ static int Main()
+ {
+ int retCode = 99;
+
+ WaitHandle[] waitHandles = null;
+
+ // Can't catch exception in v2.0. Should be fixed in Post-Orcas. VSWhidbey 543816
+ try
+ {
+ Console.WriteLine("Before WaitAny");
+ WaitHandle.WaitAny(waitHandles, 5000);
+ Console.WriteLine("After WaitAny");
+ }
+ catch (ArgumentNullException)
+ {
+ retCode = 100;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("WaitAny threw unexpected Exception.");
+ Console.WriteLine("WaitAny: {0}", ex);
+ retCode = 98;
+ }
+
+ if (retCode ==100)
+ Console.WriteLine("Test Passed");
+ else
+ Console.WriteLine("Test Failed");
+
+ return retCode;
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/nullarraymember.cs b/tests/src/baseservices/threading/waithandle/waitany/nullarraymember.cs
new file mode 100644
index 0000000000..8b24b45942
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/nullarraymember.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class Duplicates
+{
+ static int Main()
+ {
+ int retCode = 99;
+
+ WaitHandle[] waitHandles = { new Mutex(), new Mutex(), null, new Mutex() };
+
+ // Can't catch exception in v2.0. Should be fixed in Post-Orcas. VSWhidbey 543816
+ try
+ {
+ Console.WriteLine("Before WaitAny");
+ WaitHandle.WaitAny(waitHandles, 5000);
+ Console.WriteLine("After WaitAny");
+ }
+ catch (ArgumentNullException)
+ {
+ retCode = 100;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("WaitAny threw unexpected Exception.");
+ Console.WriteLine("WaitAny: {0}", ex);
+ retCode = 98;
+ }
+
+ if (retCode ==100)
+ Console.WriteLine("Test Passed");
+ else
+ Console.WriteLine("Test Failed");
+
+ return retCode;
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/nullarraymemberwaitany.csproj b/tests/src/baseservices/threading/waithandle/waitany/nullarraymemberwaitany.csproj
new file mode 100644
index 0000000000..b8267c3c4d
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/nullarraymemberwaitany.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="NullArrayMember.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/project.json b/tests/src/baseservices/threading/waithandle/waitany/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyemptyarray.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyemptyarray.csproj
new file mode 100644
index 0000000000..9621e3b064
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyemptyarray.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="EmptyArray.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex1.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex1.cs
new file mode 100644
index 0000000000..b55f8a0fde
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex1.cs
@@ -0,0 +1,65 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitAnyEx()
+ {
+ myMutex = new Mutex(false, Common.GetUniqueName());
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Testing Mutex and non-Mutex, " +
+ "not signaling the other element");
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(
+ new WaitHandle[]{myMutex,
+ new ManualResetEvent(false)}, 10000);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("Holding the Mutex");
+ // Not calling ReleaseMutex() so the Mutex becomes abandoned
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex1.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex1.csproj
new file mode 100644
index 0000000000..5d05ecf7b7
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex1.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx1.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex10.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex10.cs
new file mode 100644
index 0000000000..bb13264d4c
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex10.cs
@@ -0,0 +1,104 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ ManualResetEvent myMRE;
+
+ public WaitAnyEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAnyEx10 /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iNumElements, int iPos)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon during a wait, signaling others - " +
+ iNumElements + ", " + iPos);
+ CreateOneMutexArray(iNumElements, iPos);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexesWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh, 10000);
+ iRet = 100;
+ }
+ catch(AbandonedMutexException)
+ {
+ // Should never throw
+ Console.WriteLine("AbandonedMutexException thrown and " +
+ "shouldn't have");
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexesWait()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ else
+ ((ManualResetEvent)w).Set();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateOneMutexArray(int numElements, int iPos)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ if(i == iPos)
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ else
+ wh[i] = new ManualResetEvent(false);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex10.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex10.csproj
new file mode 100644
index 0000000000..c9b156f59f
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex10.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:2 /pos:1</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx10.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex10a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex10a.cs
new file mode 100644
index 0000000000..b92f81985e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex10a.cs
@@ -0,0 +1,104 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ ManualResetEvent myMRE;
+
+ public WaitAnyEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAnyEx10a /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iNumElements, int iPos)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon during a wait, signaling others - " +
+ iNumElements + ", " + iPos);
+ CreateOneMutexArray(iNumElements, iPos);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexesWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh);
+ iRet = 100;
+ }
+ catch(AbandonedMutexException)
+ {
+ // Should never throw
+ Console.WriteLine("AbandonedMutexException thrown and " +
+ "shouldn't have");
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexesWait()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ else
+ ((ManualResetEvent)w).Set();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateOneMutexArray(int numElements, int iPos)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ if(i == iPos)
+ wh[i] = new Mutex();
+ else
+ wh[i] = new ManualResetEvent(false);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex10a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex10a.csproj
new file mode 100644
index 0000000000..5a465b3390
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex10a.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:2 /pos:1</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx10a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex1a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex1a.cs
new file mode 100644
index 0000000000..4638d32d72
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex1a.cs
@@ -0,0 +1,65 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitAnyEx()
+ {
+ myMutex = new Mutex();
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Testing Mutex and non-Mutex, " +
+ "not signaling the other element");
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(
+ new WaitHandle[]{myMutex,
+ new ManualResetEvent(false)});
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("Holding the Mutex");
+ // Not calling ReleaseMutex() so the Mutex becomes abandoned
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex1a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex1a.csproj
new file mode 100644
index 0000000000..33f5c920c2
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex1a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx1a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex2.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex2.cs
new file mode 100644
index 0000000000..aa27c0eea1
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex2.cs
@@ -0,0 +1,68 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test
+
+class WaitAnyEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitAnyEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ myMutex = new Mutex(false, Common.GetUniqueName());
+ }
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Testing Mutex and non-Mutex, " +
+ "and signaling the other element");
+ Thread t = new Thread(new ThreadStart(this.AbandonAndSet));
+ t.Start();
+ t.Join();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(
+ new WaitHandle[]{myMutex, myMRE}, 5000);
+ Console.WriteLine("WaitAny did not throw AbandonedMutexException");
+ }
+ catch(AbandonedMutexException)
+ {
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ finally
+ {
+ myMRE.Reset();
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAndSet()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("Holding the Mutex");
+ // Signaling the Event
+ myMRE.Set();
+ // Not calling ReleaseMutex() so the Mutex becomes abandoned
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex2.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex2.csproj
new file mode 100644
index 0000000000..c8415daba8
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex2.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx2.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex2a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex2a.cs
new file mode 100644
index 0000000000..bbd2b018c6
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex2a.cs
@@ -0,0 +1,68 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test
+
+class WaitAnyEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitAnyEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ myMutex = new Mutex();
+ }
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Testing Mutex and non-Mutex, " +
+ "and signaling the other element");
+ Thread t = new Thread(new ThreadStart(this.AbandonAndSet));
+ t.Start();
+ t.Join();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(
+ new WaitHandle[]{myMutex, myMRE});
+ Console.WriteLine("WaitAny did not throw AbandonedMutexException");
+ }
+ catch(AbandonedMutexException)
+ {
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ finally
+ {
+ myMRE.Reset();
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAndSet()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ Console.WriteLine("Holding the Mutex");
+ // Signaling the Event
+ myMRE.Set();
+ // Not calling ReleaseMutex() so the Mutex becomes abandoned
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex2a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex2a.csproj
new file mode 100644
index 0000000000..f52f952db2
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex2a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx2a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex3.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex3.cs
new file mode 100644
index 0000000000..e1160c5e73
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex3.cs
@@ -0,0 +1,81 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning more than one mutex " +
+ "mix with other WaitHandles");
+ CreateArray(64);
+ myMRE = new ManualResetEvent(false);
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexes));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh, 10000);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexes()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%3)
+ {
+ case 0:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ break;
+ case 2:
+ wh[i] = new Semaphore(0,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex3.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex3.csproj
new file mode 100644
index 0000000000..31e6d15692
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex3.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx3.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex3a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex3a.cs
new file mode 100644
index 0000000000..f79cfa5cbf
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex3a.cs
@@ -0,0 +1,81 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning more than one mutex " +
+ "mix with other WaitHandles");
+ CreateArray(64);
+ myMRE = new ManualResetEvent(false);
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexes));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexes()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%3)
+ {
+ case 0:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new Mutex();
+ break;
+ case 2:
+ wh[i] = new Semaphore(0,5);
+ break;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex3a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex3a.csproj
new file mode 100644
index 0000000000..8fa024fb41
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex3a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx3a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex4.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex4.cs
new file mode 100644
index 0000000000..a67aa329c6
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex4.cs
@@ -0,0 +1,76 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning only one Mutex " +
+ "in array with other WaitHandles");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonOne));
+ t.Start();
+ t.Join();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh, 5000);
+ Console.WriteLine("WaitAny did not throw an exception");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonOne()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ {
+ w.WaitOne();
+ break;
+ }
+ }
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%3)
+ {
+ case 0:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ break;
+ case 2:
+ wh[i] = new Semaphore(0,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex4.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex4.csproj
new file mode 100644
index 0000000000..18635f0b0d
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex4.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx4.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex4a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex4a.cs
new file mode 100644
index 0000000000..e3e45567e2
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex4a.cs
@@ -0,0 +1,76 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning only one Mutex " +
+ "in array with other WaitHandles");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonOne));
+ t.Start();
+ t.Join();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh);
+ Console.WriteLine("WaitAny did not throw an exception");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonOne()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ {
+ w.WaitOne();
+ break;
+ }
+ }
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%3)
+ {
+ case 0:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new Mutex();
+ break;
+ case 2:
+ wh[i] = new Semaphore(0,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex4a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex4a.csproj
new file mode 100644
index 0000000000..d33f58d501
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex4a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx4a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex5.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex5.cs
new file mode 100644
index 0000000000..cdd75e5f19
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex5.cs
@@ -0,0 +1,85 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning only one Mutex in array " +
+ "with other WaitHandles, signaling other mutexes");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonOneAndRelease));
+ t.Start();
+ t.Join();
+ int i = -1;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ i = WaitHandle.WaitAny(wh, 5000);
+ Console.WriteLine("WaitAny did not throw AbandonedMutexExcpetion");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonOneAndRelease()
+ {
+ Mutex m = new Mutex();
+ bool bSet = false;
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ {
+ w.WaitOne();
+ if(bSet)
+ ((Mutex)w).ReleaseMutex();
+ bSet = true;
+ }
+ }
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%3)
+ {
+ case 0:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ break;
+ case 2:
+ wh[i] = new Semaphore(0,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex5.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex5.csproj
new file mode 100644
index 0000000000..7177ff221f
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex5.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx5.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex5a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex5a.cs
new file mode 100644
index 0000000000..16c4e50e61
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex5a.cs
@@ -0,0 +1,85 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandoning only one Mutex in array " +
+ "with other WaitHandles, signaling other mutexes");
+ CreateArray(64);
+ Thread t = new Thread(new ThreadStart(this.AbandonOneAndRelease));
+ t.Start();
+ t.Join();
+ int i = -1;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ i = WaitHandle.WaitAny(wh);
+ Console.WriteLine("WaitAny did not throw AbandonedMutexExcpetion");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonOneAndRelease()
+ {
+ Mutex m = new Mutex();
+ bool bSet = false;
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ {
+ w.WaitOne();
+ if(bSet)
+ ((Mutex)w).ReleaseMutex();
+ bSet = true;
+ }
+ }
+ }
+
+ private void CreateArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ switch(i%3)
+ {
+ case 0:
+ wh[i] = new ManualResetEvent(false);
+ break;
+ case 1:
+ wh[i] = new Mutex();
+ break;
+ case 2:
+ wh[i] = new Semaphore(0,5);
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex5a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex5a.csproj
new file mode 100644
index 0000000000..4f137ee80b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex5a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx5a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex6.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex6.cs
new file mode 100644
index 0000000000..0f5b58658b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex6.cs
@@ -0,0 +1,97 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAnyEx6 /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iArraySize, int iPosToAbandon)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon a particular mutex - " + iArraySize + ", " +
+ iPosToAbandon);
+ CreateMutexArray(iArraySize);
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(iPosToAbandon);
+ t.Join();
+ int i = -1;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ i = WaitHandle.WaitAny(wh, 5000);
+ if(0 == iPosToAbandon)
+ Console.WriteLine("WaitAny didn't return an " +
+ "AbandonedMutexException");
+ else
+ // Expected to pass
+ iRet = 100;
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected if pos is first
+ if(0 == iPosToAbandon)
+ iRet = 100;
+ else
+ Console.WriteLine("WaitAny threw AbandonedMutexException " +
+ "and shouldn't have!");
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex6.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex6.csproj
new file mode 100644
index 0000000000..f317a5a8f9
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex6.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:2 /pos:1</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx6.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex6a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex6a.cs
new file mode 100644
index 0000000000..89fde02a9e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex6a.cs
@@ -0,0 +1,97 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAnyEx6a /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iArraySize, int iPosToAbandon)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon a particular mutex - " + iArraySize + ", " +
+ iPosToAbandon);
+ CreateMutexArray(iArraySize);
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(iPosToAbandon);
+ t.Join();
+ int i = -1;
+ try
+ {
+ Console.WriteLine("Waiting...");
+ i = WaitHandle.WaitAny(wh);
+ if(0 == iPosToAbandon)
+ Console.WriteLine("WaitAny didn't return an " +
+ "AbandonedMutexException");
+ else
+ // Expected to pass
+ iRet = 100;
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected if pos is first
+ if(iPosToAbandon == 0)
+ iRet = 100;
+ else
+ Console.WriteLine("WaitAny threw AbandonedMutexException " +
+ "and shouldn't have!");
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex6a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex6a.csproj
new file mode 100644
index 0000000000..ed41627339
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex6a.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:64 /pos:30</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx6a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex7.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex7.cs
new file mode 100644
index 0000000000..cc3108d0f2
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex7.cs
@@ -0,0 +1,69 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon all mutexes in array");
+ CreateMutexArray(64);
+ myMRE = new ManualResetEvent(false);
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexes));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh, 10000);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexes()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex7.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex7.csproj
new file mode 100644
index 0000000000..0dbab02430
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex7.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx7.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex7a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex7a.cs
new file mode 100644
index 0000000000..903b83c372
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex7a.cs
@@ -0,0 +1,69 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ private ManualResetEvent myMRE;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon all mutexes in array");
+ CreateMutexArray(64);
+ myMRE = new ManualResetEvent(false);
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexes));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexes()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateMutexArray(int numElements)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ wh[i] = new Mutex();
+ }
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex7a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex7a.csproj
new file mode 100644
index 0000000000..2da85c8567
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex7a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx7a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex8.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex8.cs
new file mode 100644
index 0000000000..358ae5162b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex8.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon same named mutex");
+ // Create array with the same name
+ wh = new Mutex[2];
+ string sName = Common.GetUniqueName();
+ wh[0] = new Mutex(false, sName);
+ wh[1] = new Mutex(false, sName);
+
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(0);
+ t.Join();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh, 5000);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex8.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex8.csproj
new file mode 100644
index 0000000000..1485cc4959
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex8.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx8.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex8a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex8a.cs
new file mode 100644
index 0000000000..53f3fdaf53
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex8a.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This is a non-9x test.
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+
+ public static int Main()
+ {
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon same named mutex");
+ // Create array with the same name
+ wh = new Mutex[2];
+ string sName = Common.GetUniqueName();
+ wh[0] = new Mutex(false, sName);
+ wh[1] = new Mutex(false, sName);
+
+ Thread t = new Thread(new
+ ParameterizedThreadStart(this.AbandonMutexPos));
+ t.Start(0);
+ t.Join();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexPos(Object o)
+ {
+ wh[Convert.ToInt32(o)].WaitOne();
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex8a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex8a.csproj
new file mode 100644
index 0000000000..c1181bb8ae
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex8a.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx8a.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex9.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex9.cs
new file mode 100644
index 0000000000..76b3006829
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex9.cs
@@ -0,0 +1,102 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ ManualResetEvent myMRE;
+
+ public WaitAnyEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAnyEx9 /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iNumElements, int iPos)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon during a wait - " + iNumElements + ", " +
+ iPos);
+ CreateOneMutexArray(iNumElements, iPos);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexesWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh, 10000);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexesWait()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateOneMutexArray(int numElements, int iPos)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ if(i == iPos)
+ wh[i] = new Mutex(false, Common.GetUniqueName());
+ else
+ wh[i] = new ManualResetEvent(false);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex9.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex9.csproj
new file mode 100644
index 0000000000..97c724a394
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex9.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:2 /pos:1</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx9.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex9a.cs b/tests/src/baseservices/threading/waithandle/waitany/waitanyex9a.cs
new file mode 100644
index 0000000000..1c5817f9e0
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex9a.cs
@@ -0,0 +1,102 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitAnyEx
+{
+ WaitHandle[] wh;
+ ManualResetEvent myMRE;
+
+ public WaitAnyEx()
+ {
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main(string[] args)
+ {
+ // Check number of args
+ if(args.Length != 2)
+ {
+ Console.WriteLine("USAGE: WaitAnyEx9a /size:<int> /pos:<int>");
+ return -1;
+ }
+
+ // Get the args
+ int iPos=-1, iSize = -1;;
+
+ for(int i=0;i<args.Length;i++)
+ {
+ if(args[i].ToLower().StartsWith("/size:"))
+ {
+ iSize = Convert.ToInt32(args[i].Substring(6));
+ continue;
+ }
+
+ if(args[i].ToLower().StartsWith("/pos:"))
+ {
+ iPos = Convert.ToInt32(args[i].Substring(5));
+ }
+ }
+
+ WaitAnyEx wae = new WaitAnyEx();
+ return wae.Run(iSize, iPos);
+ }
+
+ private int Run(int iNumElements, int iPos)
+ {
+ int iRet = -1;
+ Console.WriteLine("Abandon during a wait - " + iNumElements + ", " +
+ iPos);
+ CreateOneMutexArray(iNumElements, iPos);
+
+ Thread t = new Thread(new ThreadStart(this.AbandonAllMutexesWait));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Waiting...");
+ int i = WaitHandle.WaitAny(wh);
+ Console.WriteLine("WaitAny did not throw an " +
+ "exception, i = " + i);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " +
+ e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonAllMutexesWait()
+ {
+ Mutex m = new Mutex();
+ foreach(WaitHandle w in wh)
+ {
+ if(w.GetType() == m.GetType())
+ w.WaitOne();
+ }
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+
+ private void CreateOneMutexArray(int numElements, int iPos)
+ {
+ wh = new WaitHandle[numElements];
+ for(int i=0;i<numElements;i++)
+ {
+ if(i == iPos)
+ wh[i] = new Mutex();
+ else
+ wh[i] = new ManualResetEvent(false);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanyex9a.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanyex9a.csproj
new file mode 100644
index 0000000000..6231667e5c
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanyex9a.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <CLRTestExecutionArguments>/size:64 /pos:30</CLRTestExecutionArguments>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitAnyEx9a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitany/waitanynullarray.csproj b/tests/src/baseservices/threading/waithandle/waitany/waitanynullarray.csproj
new file mode 100644
index 0000000000..2f0429d6ae
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitany/waitanynullarray.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="NullArray.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waithandlecommon.cs b/tests/src/baseservices/threading/waithandle/waithandlecommon.cs
new file mode 100644
index 0000000000..469e3a4a1f
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waithandlecommon.cs
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class Common
+{
+ public static string GetUniqueName()
+ {
+ string sName = Guid.NewGuid().ToString();
+ Console.WriteLine("Name created: " + sName);
+ return sName;
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitone/app.config b/tests/src/baseservices/threading/waithandle/waitone/app.config
new file mode 100644
index 0000000000..c51f616257
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/app.config
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
diff --git a/tests/src/baseservices/threading/waithandle/waitone/project.json b/tests/src/baseservices/threading/waithandle/waitone/project.json
new file mode 100644
index 0000000000..cd536cf30e
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/project.json
@@ -0,0 +1,33 @@
+{
+ "dependencies": {
+ "System.Diagnostics.Process": "4.0.0-beta-23302",
+ "System.IO": "4.0.10-beta-23302",
+ "System.IO.FileSystem": "4.0.0-beta-23302",
+ "System.IO.FileSystem.Primitives": "4.0.0-beta-23302",
+ "System.Runtime": "4.0.20-beta-23302",
+ "System.Runtime.Extensions": "4.0.10-beta-23302",
+ "System.Runtime.Handles": "4.0.0-beta-23302",
+ "System.Runtime.Loader": "4.0.0-beta-23302",
+ "System.Threading": "4.0.10-beta-23302",
+ "System.Globalization.Calendars": "4.0.0-beta-23302",
+ "System.Globalization": "4.0.10-beta-23302",
+ "System.Text.Encoding": "4.0.10-beta-23302",
+ "System.Runtime.InteropServices": "4.0.20-beta-23302",
+ "System.Collections": "4.0.10-beta-23302",
+ "System.Console": "4.0.0-beta-23302",
+ "System.Reflection": "4.0.10-beta-23302",
+ "System.Reflection.Primitives": "4.0.0-beta-23302",
+ "System.ComponentModel": "4.0.1-beta-23302",
+ "System.Xml.ReaderWriter": "4.0.11-beta-23302",
+ "System.Collections.NonGeneric": "4.0.1-beta-23302",
+ "System.Collections.Specialized": "4.0.1-beta-23302",
+ "System.Linq": "4.0.1-beta-23302",
+ "System.Linq.Queryable": "4.0.1-beta-23302",
+ "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+ "System.Xml.XmlDocument": "4.0.1-beta-23302",
+ "System.Xml.XDocument": "4.0.11-beta-23302"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex1.cs b/tests/src/baseservices/threading/waithandle/waitone/waitoneex1.cs
new file mode 100644
index 0000000000..b463ee5269
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex1.cs
@@ -0,0 +1,58 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex(false, Common.GetUniqueName());
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ return wao.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Test abandoned mutex is thrown using WaitOne");
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bool bRet = myMutex.WaitOne(10000);
+ Console.WriteLine("WaitOne did not throw an exception!");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex1.csproj b/tests/src/baseservices/threading/waithandle/waitone/waitoneex1.csproj
new file mode 100644
index 0000000000..c9585763de
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex1.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOneEx1.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex1a.cs b/tests/src/baseservices/threading/waithandle/waitone/waitoneex1a.cs
new file mode 100644
index 0000000000..b076ec6d8b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex1a.cs
@@ -0,0 +1,58 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex();
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ return wao.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Test abandoned mutex is thrown using WaitOne");
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bool bRet = myMutex.WaitOne();
+ Console.WriteLine("WaitOne did not throw an exception!");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex1a.csproj b/tests/src/baseservices/threading/waithandle/waitone/waitoneex1a.csproj
new file mode 100644
index 0000000000..92a243d8a1
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex1a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOneEx1a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex2.cs b/tests/src/baseservices/threading/waithandle/waitone/waitoneex2.cs
new file mode 100644
index 0000000000..889e1541ca
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex2.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex(false, Common.GetUniqueName());
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ return wao.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Test AbandonedMutexException is " +
+ "thrown when abandoned with a WaitAll");
+ Thread t = new Thread(new ThreadStart(this.AbandonMutexWaitAll));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bool bRet = myMutex.WaitOne(10000);
+ Console.WriteLine("WaitOne did not throw an exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexWaitAll()
+ {
+ Console.WriteLine("Abandoning Mutex");
+ WaitHandle.WaitAll(new WaitHandle[]{myMutex, new Mutex()});
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex2.csproj b/tests/src/baseservices/threading/waithandle/waitone/waitoneex2.csproj
new file mode 100644
index 0000000000..8ee808900b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex2.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOneEx2.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex2a.cs b/tests/src/baseservices/threading/waithandle/waitone/waitoneex2a.cs
new file mode 100644
index 0000000000..4fa2ddb9ca
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex2a.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex();
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ return wao.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Test AbandonedMutexException is " +
+ "thrown when abandoned with a WaitAll");
+ Thread t = new Thread(new ThreadStart(this.AbandonMutexWaitAll));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bool bRet = myMutex.WaitOne();
+ Console.WriteLine("WaitOne did not throw an exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexWaitAll()
+ {
+ Console.WriteLine("Abandoning Mutex");
+ WaitHandle.WaitAll(new WaitHandle[]{myMutex, new Mutex()});
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex2a.csproj b/tests/src/baseservices/threading/waithandle/waitone/waitoneex2a.csproj
new file mode 100644
index 0000000000..87f71ac1e2
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex2a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOneEx2a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex3.cs b/tests/src/baseservices/threading/waithandle/waitone/waitoneex3.cs
new file mode 100644
index 0000000000..85bd139354
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex3.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex(false, Common.GetUniqueName());
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ return wao.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Test AbandonedMutexException is " +
+ "thrown when abandoned with a WaitAny");
+ Thread t = new Thread(new ThreadStart(this.AbandonMutexWaitAny));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bool bRet = myMutex.WaitOne(10000);
+ Console.WriteLine("WaitOne did not throw an exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexWaitAny()
+ {
+ Console.WriteLine("Abandoning Mutex");
+ WaitHandle.WaitAny(new WaitHandle[]{new ManualResetEvent(false), myMutex});
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex3.csproj b/tests/src/baseservices/threading/waithandle/waitone/waitoneex3.csproj
new file mode 100644
index 0000000000..99a15a219c
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex3.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOneEx3.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex3a.cs b/tests/src/baseservices/threading/waithandle/waitone/waitoneex3a.cs
new file mode 100644
index 0000000000..cefbda2670
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex3a.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+ private ManualResetEvent myMRE;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex();
+ myMRE = new ManualResetEvent(false);
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ return wao.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Test AbandonedMutexException is " +
+ "thrown when abandoned with a WaitAny");
+ Thread t = new Thread(new ThreadStart(this.AbandonMutexWaitAny));
+ t.Start();
+ myMRE.WaitOne();
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bool bRet = myMutex.WaitOne();
+ Console.WriteLine("WaitOne did not throw an exception, bRet = " + bRet);
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonMutexWaitAny()
+ {
+ Console.WriteLine("Abandoning Mutex");
+ WaitHandle.WaitAny(new WaitHandle[]{new ManualResetEvent(false), myMutex});
+ myMRE.Set();
+ Thread.Sleep(1000);
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex3a.csproj b/tests/src/baseservices/threading/waithandle/waitone/waitoneex3a.csproj
new file mode 100644
index 0000000000..493854749b
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex3a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOneEx3a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex4.cs b/tests/src/baseservices/threading/waithandle/waitone/waitoneex4.cs
new file mode 100644
index 0000000000..0e79432f42
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex4.cs
@@ -0,0 +1,57 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This test is for non-9x platforms. 9x does not throw an AbandonedMutexException
+// when it is not actively waiting.
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex(false, Common.GetUniqueName());
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ return wao.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Test abandoned mutex is thrown using WaitOne");
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ t.Join();
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bool bRet = myMutex.WaitOne(10000);
+ Console.WriteLine("WaitOne did not throw an exception!");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex4.csproj b/tests/src/baseservices/threading/waithandle/waitone/waitoneex4.csproj
new file mode 100644
index 0000000000..23ea8fba59
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex4.csproj
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOneEx4.cs" />
+ <Compile Include="..\WaitHandleCommon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex4a.cs b/tests/src/baseservices/threading/waithandle/waitone/waitoneex4a.cs
new file mode 100644
index 0000000000..a9ec241706
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex4a.cs
@@ -0,0 +1,57 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+
+// This test is for non-9x platforms. 9x does not throw an AbandonedMutexException
+// when it is not actively waiting.
+
+class WaitOneEx
+{
+ private Mutex myMutex;
+
+ public WaitOneEx()
+ {
+ myMutex = new Mutex();
+ }
+
+ public static int Main()
+ {
+ WaitOneEx wao = new WaitOneEx();
+ return wao.Run();
+ }
+
+ private int Run()
+ {
+ int iRet = -1;
+ Console.WriteLine("Test abandoned mutex is thrown using WaitOne");
+ Thread t = new Thread(new ThreadStart(this.AbandonTheMutex));
+ t.Start();
+ t.Join();
+ try
+ {
+ Console.WriteLine("Wait on an abandoned mutex");
+ bool bRet = myMutex.WaitOne();
+ Console.WriteLine("WaitOne did not throw an exception!");
+ }
+ catch(AbandonedMutexException)
+ {
+ // Expected
+ iRet = 100;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Unexpected exception thrown: " + e.ToString());
+ }
+ Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed");
+ return iRet;
+ }
+
+ private void AbandonTheMutex()
+ {
+ Console.WriteLine("Acquire the Mutex");
+ myMutex.WaitOne();
+ }
+}
diff --git a/tests/src/baseservices/threading/waithandle/waitone/waitoneex4a.csproj b/tests/src/baseservices/threading/waithandle/waitone/waitoneex4a.csproj
new file mode 100644
index 0000000000..13af2650f0
--- /dev/null
+++ b/tests/src/baseservices/threading/waithandle/waitone/waitoneex4a.csproj
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <!-- Add Compile Object Here -->
+ <Compile Include="WaitOneEx4a.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+ <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+ </PropertyGroup>
+</Project> \ No newline at end of file