diff options
author | Aleksey Kliger (λgeek) <alklig@microsoft.com> | 2020-10-09 17:34:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-09 17:34:28 +0300 |
commit | af315f44c40dfb8767d64920bae2cdb8da7cc3f8 (patch) | |
tree | d8df24006afb0ed1927165ac16c5b6d00b79eb73 | |
parent | ca11fb0fd819a1e32565b0d626506f66fb9fd272 (diff) |
[2020-02][corlib] ThreadAbortException protection for ArraySortHelper (#20468)mono-6.12.0.102
* [test] Abort a thread doing a long-running Array.Sort
The custom comparer is wrapped in a try/finally. Verify that it doesn't turn
thread abort exceptions into some other exception.
Regression test for https://github.com/mono/mono/issues/15418
* Bump corert
To pick up fix for mono/mono#15418
* disable new test on platforms without Thread.Abort
m--------- | external/corert | 0 | ||||
-rw-r--r-- | mcs/class/corlib/Test/System/ArrayTest.cs | 62 |
2 files changed, 62 insertions, 0 deletions
diff --git a/external/corert b/external/corert -Subproject ffcd7990d87e560c63413293c8efe1d1fc4e358 +Subproject 11136ad55767485063226be08cfbd32ed574ca4 diff --git a/mcs/class/corlib/Test/System/ArrayTest.cs b/mcs/class/corlib/Test/System/ArrayTest.cs index 819cb871749..3c168093cc1 100644 --- a/mcs/class/corlib/Test/System/ArrayTest.cs +++ b/mcs/class/corlib/Test/System/ArrayTest.cs @@ -12,6 +12,7 @@ using System; using System.Collections; using System.Globalization; using System.Reflection; +using System.Threading; using System.Collections.Generic; namespace MonoTests.System @@ -3745,5 +3746,66 @@ public class ArrayTest Assert.Throws<NotSupportedException> (() => { var _ = x.GetValue (0); }, "#2"); Assert.Throws<NotSupportedException> (() => { x.SetValue (0, 0); }, "#3"); } + + +#if MONO_FEATURE_THREAD_ABORT + public struct J + { + public int i; + + public J(int i_) { i = i_; } + } + + struct JComp : IComparer<J> + { + public int Compare(J x, J y) + { + int val = 0; + Thread.Sleep (Timeout.Infinite); + return val; + } + } + + class ArraySortAbortData { + internal ManualResetEventSlim mre; + internal bool threw; + + internal ArraySortAbortData () { + mre = new ManualResetEventSlim (); + threw = false; + } + } + + [Test] + public void ArraySortAbort () + { + var d = new ArraySortAbortData(); + var t = new Thread(RunArraySort); + t.Start(d); + d.mre.Wait(); + Thread.Sleep(400); + t.Abort(); + t.Join(); + Assert.IsFalse (d.threw); + } + + public static void RunArraySort(object data) + { + var d = data as ArraySortAbortData; + int n = 10; + var a = new J[n]; + for (int i = 0; i < n; ++i) + { + a[i] = new J(n - i); + } + d.mre.Set(); + try { + Array.Sort(a, 0, n, new JComp()); + } catch (InvalidOperationException) { + // t.Abort in ArraySortAbort should _not_ end up here + d.threw = true; + } + } +#endif } } |