diff --git a/src/coreclr/tests/src/baseservices/exceptions/stackoverflow/stackoverflow.cs b/src/coreclr/tests/src/baseservices/exceptions/stackoverflow/stackoverflow.cs index 2cb9aa6ae82f49..3a4a363c7425bb 100644 --- a/src/coreclr/tests/src/baseservices/exceptions/stackoverflow/stackoverflow.cs +++ b/src/coreclr/tests/src/baseservices/exceptions/stackoverflow/stackoverflow.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; using System.Threading; +using System.Runtime.CompilerServices; namespace TestStackOverflow { @@ -67,39 +68,47 @@ struct LargeStruct65536 } class Program { + [MethodImpl(MethodImplOptions.NoInlining)] static void InfiniteRecursionA() { InfiniteRecursionB(); } + [MethodImpl(MethodImplOptions.NoInlining)] static void InfiniteRecursionB() { InfiniteRecursionC(); } + + [MethodImpl(MethodImplOptions.NoInlining)] static void InfiniteRecursionC() { InfiniteRecursionA(); } + [MethodImpl(MethodImplOptions.NoInlining)] static void InfiniteRecursionA2() { LargeStruct65536 s; InfiniteRecursionB2(); } + [MethodImpl(MethodImplOptions.NoInlining)] static void InfiniteRecursionB2() { LargeStruct65536 s; InfiniteRecursionC2(); } + [MethodImpl(MethodImplOptions.NoInlining)] static void InfiniteRecursionC2() { LargeStruct65536 s; InfiniteRecursionA2(); } - static void MainThreadTest(bool smallframe) + [MethodImpl(MethodImplOptions.NoInlining)] + static void Test(bool smallframe) { if (smallframe) { @@ -116,16 +125,7 @@ static void SecondaryThreadsTest(bool smallframe) Thread[] threads = new Thread[32]; for (int i = 0; i < threads.Length; i++) { - threads[i] = new Thread(() => { - if (smallframe) - { - InfiniteRecursionA(); - } - else - { - InfiniteRecursionA2(); - } - }); + threads[i] = new Thread(() => Test(smallframe)); threads[i].Start(); } @@ -144,7 +144,7 @@ static void Main(string[] args) } else if (args[1] == "main") { - MainThreadTest(smallframe); + Test(smallframe); } } } diff --git a/src/coreclr/tests/src/baseservices/exceptions/stackoverflow/stackoverflowtester.cs b/src/coreclr/tests/src/baseservices/exceptions/stackoverflow/stackoverflowtester.cs index f30305658c1007..d8326ff6666bf2 100644 --- a/src/coreclr/tests/src/baseservices/exceptions/stackoverflow/stackoverflowtester.cs +++ b/src/coreclr/tests/src/baseservices/exceptions/stackoverflow/stackoverflowtester.cs @@ -77,6 +77,12 @@ static bool TestStackOverflowSmallFrameMainThread() return false; } + if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.Test(Boolean)"))) + { + Console.WriteLine("Missing \"Test\" method frame"); + return false; + } + if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA()"))) { Console.WriteLine("Missing \"InfiniteRecursionA\" method frame"); @@ -112,9 +118,9 @@ static bool TestStackOverflowLargeFrameMainThread() return false; } - if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.MainThreadTest(Boolean)"))) + if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.Test(Boolean)"))) { - Console.WriteLine("Missing \"MainThreadTest\" method frame"); + Console.WriteLine("Missing \"Test\" method frame"); return false; } @@ -147,9 +153,9 @@ static bool TestStackOverflowSmallFrameSecondaryThread() List lines; if (TestStackOverflow("stackoverflow", "smallframe secondary", out lines)) { - if (!lines[lines.Count - 1].EndsWith("at System.Threading.ThreadHelper.ThreadStart()")) + if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)"))) { - Console.WriteLine("Missing \"System.Threading.ThreadHelper.ThreadStart\" method frame at the last line"); + Console.WriteLine("Missing \"TestStackOverflow.Program.Test\" method frame"); return false; } @@ -182,9 +188,9 @@ static bool TestStackOverflowLargeFrameSecondaryThread() List lines; if (TestStackOverflow("stackoverflow", "largeframe secondary", out lines)) { - if (!lines[lines.Count - 1].EndsWith("at System.Threading.ThreadHelper.ThreadStart()")) + if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)"))) { - Console.WriteLine("Missing \"System.Threading.ThreadHelper.ThreadStart\" method frame at the last line"); + Console.WriteLine("Missing \"TestStackOverflow.Program.Test\" method frame"); return false; }