Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -25,7 +25,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if FEATURE_MONO_CAS
#if MONO_FEATURE_CAS
using System;
using System.Security;
@@ -168,4 +168,4 @@ namespace MonoCasTests.System.Threading {
}
}
#endif
#endif

View File

@@ -20,6 +20,7 @@ namespace MonoTests.System.Threading
{
public int id;
public Mutex mut;
public bool abandoned_exception;
public ConcClass(int id,Mutex mut)
{
this.id = id;
@@ -63,7 +64,12 @@ namespace MonoTests.System.Threading
public void WaitAndForget()
{
this.Wait();
try {
this.Wait();
} catch (AbandonedMutexException) {
this.abandoned_exception = true;
}
this.marker = id;
}
public void WaitAndWait()
@@ -137,7 +143,7 @@ namespace MonoTests.System.Threading
}
[Test]
public void TestWaitAndFoget1()
public void TestWaitAndForget1()
{
Mutex Sem = new Mutex(false);
ConcClassLoop class1 = new ConcClassLoop(1,Sem);
@@ -148,9 +154,11 @@ namespace MonoTests.System.Threading
try {
thread1.Start();
TestUtil.WaitForNotAlive (thread1, "t1");
Assert.IsFalse (class1.abandoned_exception, "e1");
thread2.Start();
TestUtil.WaitForNotAlive (thread2, "t2");
Assert.IsTrue (class2.abandoned_exception, "e2");
Assert.AreEqual (class2.id, class2.marker);
} finally {

View File

@@ -29,9 +29,6 @@ using System.Threading;
using NUnit;
using NUnit.Framework;
#if !MOBILE
using NUnit.Framework.SyntaxHelpers;
#endif
namespace MonoTests.System.Threading
{

View File

@@ -13,6 +13,7 @@ using System;
using System.Globalization;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using System.Collections.Generic;
using SD = System.Diagnostics;
@@ -908,6 +909,23 @@ namespace MonoTests.System.Threading
}
#endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
[Test]
public void SetNameInThreadPoolThread ()
{
Task t = Task.Run (delegate () {
Thread.CurrentThread.Name = "ThreadName1";
Assert.AreEqual (Thread.CurrentThread.Name, "ThreadName1", "#1");
try {
Thread.CurrentThread.Name = "ThreadName2";
Assert.Fail ("#2");
} catch (InvalidOperationException) {
}
});
t.Wait ();
}
void CheckIsRunning (string s, Thread t)
{
int c = counter;

View File

@@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using NUnit.Framework;
@@ -395,6 +396,148 @@ namespace MonoTests.System.Threading {
}
}
[Test]
public void WaitOneWithAbandonedMutex ()
{
using (var m = new Mutex (false)) {
var thread1 = new Thread (() => {
m.WaitOne ();
});
thread1.Start ();
thread1.Join (1000);
try {
m.WaitOne ();
Assert.Fail ("Expected AbandonedMutexException");
} catch (AbandonedMutexException) {
}
// Current thread should own the Mutex now
var signalled = false;
var thread2 = new Thread (() => {
signalled = m.WaitOne (100);
});
thread2.Start ();
thread2.Join (1000);
Assert.IsFalse (signalled);
// Since this thread owns the Mutex releasing it shouldn't fail
m.ReleaseMutex ();
// The Mutex should now be unowned
try {
m.ReleaseMutex ();
Assert.Fail ("Expected ApplicationException");
} catch (ApplicationException) {
}
}
}
[Test]
public void WaitOneWithAbandonedMutexAndMultipleThreads ()
{
using (var m = new Mutex (true)) {
var nonAbandoned = 0;
var abandoned = 0;
var n = 0;
var threads = new List<Thread> ();
for (int i = 0; i < 50; i++) {
var thread = new Thread (() => {
try {
m.WaitOne ();
nonAbandoned++;
} catch (AbandonedMutexException) {
abandoned++;
}
if (((n++) % 5) != 0)
m.ReleaseMutex ();
});
thread.Start ();
threads.Add (thread);
}
m.ReleaseMutex ();
foreach (var thread in threads) {
if (!thread.Join (1000)) {
Assert.Fail ("Timed out");
}
}
Assert.AreEqual (40, nonAbandoned);
Assert.AreEqual (10, abandoned);
}
}
[Test]
public void WaitAnyWithSecondMutexAbandoned ()
{
using (var m1 = new Mutex (false)) {
using (var m2 = new Mutex (false)) {
var mainProceed = false;
var thread2Proceed = false;
var thread1 = new Thread (() => {
m2.WaitOne ();
});
var thread2 = new Thread (() => {
m1.WaitOne ();
mainProceed = true;
while (!thread2Proceed) {
Thread.Sleep (10);
}
m1.ReleaseMutex ();
});
thread1.Start ();
thread1.Join (1000);
thread2.Start ();
while (!mainProceed) {
Thread.Sleep (10);
}
try {
WaitHandle.WaitAny (new WaitHandle [] { m1, m2 });
Assert.Fail ("Expected AbandonedMutexException");
} catch (AbandonedMutexException e) {
Assert.AreEqual (1, e.MutexIndex);
Assert.AreEqual (m2, e.Mutex);
} finally {
thread2Proceed = true;
thread2.Join (1000);
}
// Current thread should own the second Mutex now
var signalled = -1;
var thread3 = new Thread (() => {
signalled = WaitHandle.WaitAny (new WaitHandle [] { m1, m2 }, 0);
});
thread3.Start ();
thread3.Join (1000);
Assert.AreEqual (0, signalled);
// Since this thread owns the second Mutex releasing it shouldn't fail
m2.ReleaseMutex ();
// Second Mutex should now be unowned
try {
m2.ReleaseMutex ();
Assert.Fail ("Expected ApplicationException");
} catch (ApplicationException) {
}
// .NET allows the first Mutex which is now abandoned to be released multiple times by this thread
m1.ReleaseMutex ();
m1.ReleaseMutex ();
}
}
}
[Test]
[ExpectedException (typeof (AbandonedMutexException))]
public void WaitAllWithOneAbandonedMutex ()
{
using (var m1 = new Mutex (false)) {
using (var m2 = new Mutex (false)) {
var thread = new Thread (() => {
m1.WaitOne ();
});
thread.Start ();
thread.Join (1000);
WaitHandle.WaitAll (new WaitHandle [] { m1, m2 });
}
}
}
#if MONO_FEATURE_THREAD_SUSPEND_RESUME
[Test]
public void WaitOneWithTimeoutAndSpuriousWake ()