Skip to content

Commit

Permalink
Fix stackoverflowtester per Mark's PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
trylek committed Oct 29, 2023
1 parent 2d85c95 commit 38e77a4
Showing 1 changed file with 88 additions and 141 deletions.
229 changes: 88 additions & 141 deletions src/tests/baseservices/exceptions/stackoverflow/stackoverflowtester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace TestStackOverflow
{
public class Program
{
static bool TestStackOverflow(string testName, string testArgs, out List<string> stderrLines)
static void TestStackOverflow(string testName, string testArgs, out List<string> stderrLines)
{
Console.WriteLine($"Running {testName} test({testArgs})");
List<string> lines = new List<string>();
Expand Down Expand Up @@ -56,197 +56,144 @@ static bool TestStackOverflow(string testName, string testArgs, out List<string>
expectedListBuilder.Append($"{separator}0x{code:X8}");
separator = " or ";
});
Console.WriteLine($"Exit code: 0x{testProcess.ExitCode:X8}, expected {expectedListBuilder.ToString()}");
return false;
throw new Exception($"Exit code: 0x{testProcess.ExitCode:X8}, expected {expectedListBuilder.ToString()}");
}

if (lines[0] != "Stack overflow.")
{
Console.WriteLine("Missing \"Stack overflow.\" at the first line");
return false;
throw new Exception("Missing \"Stack overflow.\" at the first line");
}

return true;
}

[Fact]
public static bool TestStackOverflowSmallFrameMainThread()
public static void TestStackOverflowSmallFrameMainThread()
{
List<string> lines;
if (TestStackOverflow("stackoverflow", "smallframe main", out lines))
{
if (!lines[lines.Count - 1].EndsWith(".Main()"))
{
Console.WriteLine("Missing \"Main\" method frame at the last line");
return false;
}
TestStackOverflow("stackoverflow", "smallframe main", out List<string> lines);

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");
return false;
}
if (!lines[lines.Count - 1].EndsWith(".Main(System.String[])"))
{
throw new Exception("Missing \"Main\" method frame at the last line");
}

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB()")))
{
Console.WriteLine("Missing \"InfiniteRecursionB\" method frame");
return false;
}
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.Test(Boolean)")))
{
throw new Exception("Missing \"Test\" method frame");
}

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC()")))
{
Console.WriteLine("Missing \"InfiniteRecursionC\" method frame");
return false;
}
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA()")))
{
throw new Exception("Missing \"InfiniteRecursionA\" method frame");
}

return true;
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB()")))
{
throw new Exception("Missing \"InfiniteRecursionB\" method frame");
}

return false;
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC()")))
{
throw new Exception("Missing \"InfiniteRecursionC\" method frame");
}
}

[Fact]
public static bool TestStackOverflowLargeFrameMainThread()
public static void TestStackOverflowLargeFrameMainThread()
{
List<string> lines;
if (TestStackOverflow("stackoverflow", "largeframe main", out lines))
{
if (!lines[lines.Count - 1].EndsWith("at TestStackOverflow.Program.Main(System.String[])"))
{
Console.WriteLine("Missing \"Main\" method frame at the last line");
return false;
}

if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.Test(Boolean)")))
{
Console.WriteLine("Missing \"Test\" method frame");
return false;
}
TestStackOverflow("stackoverflow", "largeframe main", out List<string> lines);

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA2()")))
{
Console.WriteLine("Missing \"InfiniteRecursionA2\" method frame");
return false;
}
if (!lines[lines.Count - 1].EndsWith("at TestStackOverflow.Program.Main(System.String[])"))
{
throw new Exception("Missing \"Main\" method frame at the last line");
}

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB2()")))
{
Console.WriteLine("Missing \"InfiniteRecursionB2\" method frame");
return false;
}
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.Test(Boolean)")))
{
throw new Exception("Missing \"Test\" method frame");
}

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC2()")))
{
Console.WriteLine("Missing \"InfiniteRecursionC2\" method frame");
return false;
}
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA2()")))
{
throw new Exception("Missing \"InfiniteRecursionA2\" method frame");
}

return true;
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB2()")))
{
throw new Exception("Missing \"InfiniteRecursionB2\" method frame");
}

return false;
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC2()")))
{
throw new Exception("Missing \"InfiniteRecursionC2\" method frame");
}
}

[Fact]
public static bool TestStackOverflowSmallFrameSecondaryThread()
public static void TestStackOverflowSmallFrameSecondaryThread()
{
List<string> lines;
if (TestStackOverflow("stackoverflow", "smallframe secondary", out lines))
{
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)")))
{
Console.WriteLine("Missing \"TestStackOverflow.Program.Test\" method frame");
return false;
}

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA()")))
{
Console.WriteLine("Missing \"InfiniteRecursionA\" method frame");
return false;
}
TestStackOverflow("stackoverflow", "smallframe secondary", out List<string> lines);

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB()")))
{
Console.WriteLine("Missing \"InfiniteRecursionB\" method frame");
return false;
}
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)")))
{
throw new Exception("Missing \"TestStackOverflow.Program.Test\" method frame");
}

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC()")))
{
Console.WriteLine("Missing \"InfiniteRecursionC\" method frame");
return false;
}
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA()")))
{
throw new Exception("Missing \"InfiniteRecursionA\" method frame");
}

return true;
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB()")))
{
throw new Exception("Missing \"InfiniteRecursionB\" method frame");
}

return false;
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC()")))
{
throw new Exception("Missing \"InfiniteRecursionC\" method frame");
}
}

[Fact]
public static bool TestStackOverflowLargeFrameSecondaryThread()
public static void TestStackOverflowLargeFrameSecondaryThread()
{
List<string> lines;
if (TestStackOverflow("stackoverflow", "largeframe secondary", out lines))
{
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)")))
{
Console.WriteLine("Missing \"TestStackOverflow.Program.Test\" method frame");
return false;
}

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA2()")))
{
Console.WriteLine("Missing \"InfiniteRecursionA2\" method frame");
return false;
}
TestStackOverflow("stackoverflow", "largeframe secondary", out List<string> lines);

if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.InfiniteRecursionB2()")))
{
Console.WriteLine("Missing \"InfiniteRecursionB2\" method frame");
return false;
}
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)")))
{
throw new Exception("Missing \"TestStackOverflow.Program.Test\" method frame");
}

if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.InfiniteRecursionC2()")))
{
Console.WriteLine("Missing \"InfiniteRecursionC2\" method frame");
return false;
}
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA2()")))
{
throw new Exception("Missing \"InfiniteRecursionA2\" method frame");
}

return true;
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.InfiniteRecursionB2()")))
{
throw new Exception("Missing \"InfiniteRecursionB2\" method frame");
}

return false;
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.InfiniteRecursionC2()")))
{
throw new Exception("Missing \"InfiniteRecursionC2\" method frame");
}
}

[Fact]
public static bool TestStackOverflow3()
public static void TestStackOverflow3()
{
List<string> lines;
if (TestStackOverflow("stackoverflow3", "", out lines))
{
if (!lines[lines.Count - 1].EndsWith("at TestStackOverflow3.Program.Main()"))
{
Console.WriteLine("Missing \"Main\" method frame at the last line");
return false;
}
TestStackOverflow("stackoverflow3", "", out List<string> lines);

if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow3.Program.Execute(System.String)")))
{
Console.WriteLine("Missing \"Execute\" method frame");
return false;
}
if (!lines[lines.Count - 1].EndsWith("at TestStackOverflow3.Program.Main()"))
{
throw new Exception("Missing \"Main\" method frame at the last line");
}

return true;
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow3.Program.Execute(System.String)")))
{
throw new Exception("Missing \"Execute\" method frame");
}

return false;
}
}
}

0 comments on commit 38e77a4

Please sign in to comment.