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 9 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
92 changes: 17 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,20 @@ private void TestSetShutdown(int totalTestsToRun)

if (_curTestSet.DebugBreakOnTestHang)
{
TestIsHungDebugBreak();
string msg = "Test hang because of timeout";
Console.WriteLine(msg);
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, msg);
Debugger.Break();
}
else
{
string msg = "Throw exception because of timeout";
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, msg);
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 +1007,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 +1153,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 +1264,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 +1272,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
2 changes: 1 addition & 1 deletion src/tests/GC/Stress/Framework/ReliabilityTestSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ReliabilityTestSet
private string _friendlyName;
private bool _enablePerfCounters = true, _disableLogging = false, _installDetours = false;
private bool _suppressConsoleOutputFromTests = false;
private bool _debugBreakOnTestHang = true;
private bool _debugBreakOnTestHang = false;
private bool _debugBreakOnBadTest = false;
private bool _debugBreakOnOutOfMemory = false;
private bool _debugBreakOnPathTooLong = false;
Expand Down
3 changes: 1 addition & 2 deletions src/tests/GC/Stress/finalization.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
installDetours="false"
minimumTests="0"
minMaxTestUseCPUCount="true"
suppressConsoleOutputFromTests="true"
debugBreakOnTestHang="true">
suppressConsoleOutputFromTests="true">

<Assembly id="GCPerfSim - SOH Allocations Finalizable Objects."
successCode="100"
Expand Down
3 changes: 1 addition & 2 deletions src/tests/GC/Stress/loh.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
installDetours="false"
minimumTests="0"
minMaxTestUseCPUCount="true"
suppressConsoleOutputFromTests="true"
debugBreakOnTestHang="true">
suppressConsoleOutputFromTests="true">

<!-- Add GCPerfSim with No live data on the LOH -->
<Assembly id="GCPerfSim - LOH No Live Data."
Expand Down
3 changes: 1 addition & 2 deletions src/tests/GC/Stress/poh.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
installDetours="false"
minimumTests="0"
minMaxTestUseCPUCount="true"
suppressConsoleOutputFromTests="true"
debugBreakOnTestHang="true">
suppressConsoleOutputFromTests="true">

<!-- Add GCPerfSim with No live data on the POH -->
<Assembly id="GCPerfSim - POH No Live Data."
Expand Down