Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all kernel32.dll references and debug breakpoints #108647

Merged
merged 13 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/tests/GC/Stress/Framework/RFLogging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ private void LogWorker()
}
catch (IOException e)
{
ReliabilityFramework.MyDebugBreak(String.Format("LogWorker IOException:{0}", e.ToString()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's throw the exception here so that we can take a dump

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the debugger break is set to true, we should set a debug break point here and if not, log and throw an exception.

//Disk may be full so simply stop logging
throw new Exception("Fail to write message to log file: " + e.Message);
}
}

Expand Down Expand Up @@ -120,7 +120,6 @@ private void LogWorker()
}
catch (IOException e)
{
ReliabilityFramework.MyDebugBreak(String.Format("LogWorker IOException:{0}", e.ToString()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to throw an exception here still after logging?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: if debugger is present => break else, log and throw an exception.

}
}
}
Expand Down
89 changes: 14 additions & 75 deletions src/tests/GC/Stress/Framework/ReliabilityFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ public static int Main(string[] args)
{
rf.HandleOom(e, "Running tests");
}
catch (TimeoutException e)
{
throw e;
}
catch (Exception e)
{
Exception eTemp = e.InnerException;
Expand Down Expand Up @@ -274,24 +278,13 @@ public void HandleOom(Exception e, string message)
try
{
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.Tests, String.Format("Exception while running tests: {0}", e));
if (_curTestSet.DebugBreakOnOutOfMemory)
{
OomExceptionCausedDebugBreak();
}
}
catch (OutOfMemoryException)
{
// hang and let someone debug if we can't even break in...
Thread.CurrentThread.Join();
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.Tests, "Out of memory");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw here to pick up the dump on the scripts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same logic here - if debugger present => break.

}
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void OomExceptionCausedDebugBreak()
{
MyDebugBreak("Harness");
}

/// <summary>
/// Runs the reliability tests. Called from Main with the name of the configuration file we should be using.
/// All code in here runs in our starting app domain.
Expand Down Expand Up @@ -506,15 +499,6 @@ public int RunReliabilityTests(string testConfig, bool doReplay)
return (99);
}

[DllImport("kernel32.dll")]
private extern static void DebugBreak();

[DllImport("kernel32.dll")]
private extern static bool IsDebuggerPresent();

[DllImport("kernel32.dll")]
private extern static void OutputDebugString(string debugStr);

/// <summary>
/// Checks to see if we should block all execution due to a fatal error
/// (when DebugBreak is not available on win9x or running outside the debugger).
Expand All @@ -533,27 +517,6 @@ private static void NoExitPoll()
}
}
}
internal static void MyDebugBreak(string extraData)
{
if (IsDebuggerPresent())
{
Console.WriteLine(string.Format("DebugBreak: {0}", extraData));
DebugBreak();
}
{
// We need to stop the process now,
// but all the threads are still running
try
{
Console.WriteLine("MyDebugBreak called, stopping process... {0}", extraData);
}
finally
{
s_fNoExit = true;
Thread.CurrentThread.Join();
}
}
}

/// <summary>
/// Calculates the total number of tests to be run based upon the maximum
Expand Down Expand Up @@ -780,7 +743,7 @@ private void TestStarter()
Thread.Sleep(250); // give the CPU a bit of a rest if we don't need to start a new test.
if (_curTestSet.DebugBreakOnMissingTest && DateTime.Now.Subtract(_startTime) > minTimeToStartTest)
{
NewTestsNotStartingDebugBreak();
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.TestStarter, String.Format("New tests not starting"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add debug break conditional functionality.

}
}
}
Expand All @@ -799,12 +762,6 @@ private void TestStarter()
TestSetShutdown(totalTestsToRun);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void NewTestsNotStartingDebugBreak()
{
MyDebugBreak("Tests haven't been started in a long time!");
}

/// <summary>
/// Shuts down the current test set, waiting for tests to finish, etc...
/// </summary>
Expand Down Expand Up @@ -882,20 +839,17 @@ private void TestSetShutdown(int totalTestsToRun)

if (_curTestSet.DebugBreakOnTestHang)
{
TestIsHungDebugBreak();
Console.WriteLine("Test hang.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be via the logger and so should be the case below.

Debugger.Break();
}
else
{
Console.WriteLine("Time limit reached.");
throw new TimeoutException("Time limit reached.");
}
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void TestIsHungDebugBreak()
{
string msg = String.Format("break");
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, msg);

MyDebugBreak("TestHang");
}

/// <summary>
/// Starts the test passed. The test should already be loaded into an app domain.
/// </summary>
Expand Down Expand Up @@ -1050,7 +1004,7 @@ private void StartTestWorker(object test)
{
if (_curTestSet.DebugBreakOnPathTooLong)
{
MyDebugBreak("Path too long");
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.Tests, "Path too long");
}
}
catch (OutOfMemoryException e)
Expand Down Expand Up @@ -1196,12 +1150,6 @@ private void StartTestWorker(object test)
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void UnexpectedThreadAbortDebugBreak()
{
MyDebugBreak("Unexpected Thread Abort");
}

/// <summary>
/// Called after a test has finished executing.
/// </summary>
Expand Down Expand Up @@ -1313,10 +1261,6 @@ private void TestPreLoader(ReliabilityTest test, string[] paths)
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.Tests, msg);
test.ConcurrentCopies = 0;
test.TestLoadFailed = true;
if (_curTestSet.DebugBreakOnBadTest)
{
BadTestDebugBreak(msg);
}

// crash on exceptions when running as a unit test.
if (IsRunningAsUnitTest)
Expand All @@ -1325,11 +1269,6 @@ private void TestPreLoader(ReliabilityTest test, string[] paths)
Interlocked.Decrement(ref LoadingCount);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void BadTestDebugBreak(string msg)
{
MyDebugBreak(msg);
}

[MethodImpl(MethodImplOptions.NoInlining)]
WeakReference UnloadAssemblyLoadContextInner(ReliabilityTest test)
Expand Down