Skip to content

Commit

Permalink
Fix the stackoverflow test output checks (#35914)
Browse files Browse the repository at this point in the history
* Fix the stackoverflow test output checks

The System.Threading.ThreadHelper.ThreadStart can tail call the
System.Threading.ExecutionContext.RunInternal (and some other methods in
the runtime as well) and thus it would not be visible on the stack
trace. So the fix is to not to look at the System.Threading.ThreadHelper.ThreadStart
in the stack trace and use a method in the test itself instead. Since
the test is compiled with optimizations disabled, JIT should not do any
"interesting" things.

* Add NoInlining attribute and do a little unification
  • Loading branch information
janvorli authored May 7, 2020
1 parent 5199a8c commit 6985ce6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
}

Expand All @@ -144,7 +144,7 @@ static void Main(string[] args)
}
else if (args[1] == "main")
{
MainThreadTest(smallframe);
Test(smallframe);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -147,9 +153,9 @@ static bool TestStackOverflowSmallFrameSecondaryThread()
List<string> 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;
}

Expand Down Expand Up @@ -182,9 +188,9 @@ static bool TestStackOverflowLargeFrameSecondaryThread()
List<string> 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;
}

Expand Down

0 comments on commit 6985ce6

Please sign in to comment.