Skip to content

Tests ran counter #111145

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

Merged
merged 6 commits into from
Feb 3, 2025
Merged
Changes from 2 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
35 changes: 34 additions & 1 deletion src/tests/GC/Stress/Framework/ReliabilityFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Linq;

using System.Runtime.Loader;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is needed


delegate void TestPreLoaderDelegate(ReliabilityTest test, string[] paths);
delegate void AssemblyLoadContextUnloadDelegate();
Expand Down Expand Up @@ -119,6 +120,8 @@ public class ReliabilityFramework
private int _reportedFailCnt = 0;
private RFLogging _logger = new RFLogging();
private DateTime _lastLogTime = DateTime.Now;
private Dictionary<string, uint> _testRanCounter = new();
private object _testRanCounterLock = new();

// static members
private static int s_seed = (int)System.DateTime.Now.Ticks;
Expand Down Expand Up @@ -161,6 +164,11 @@ public static int Main(string[] args)

ReliabilityFramework rf = new ReliabilityFramework();
rf._logger.WriteToInstrumentationLog(null, LoggingLevels.StartupShutdown, "Started");

Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs args) => {
Copy link
Member

Choose a reason for hiding this comment

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

NIT: Since you aren't using either of the parameters of the delegate, you could easily set them to _ to indicate that they aren't used i.e.,

csharp Console.CancelKeyPress += (object _, ConsoleCancelEventArgs _) => { .. }

rf.RecordTestRanCount();
};

var configVars = GC.GetConfigurationVariables();
foreach (var kvp in configVars)
{
Expand Down Expand Up @@ -305,7 +313,7 @@ public static int Main(string[] args)
}

NoExitPoll();

rf.RecordTestRanCount();
rf._logger.WriteToInstrumentationLog(null, LoggingLevels.StartupShutdown, String.Format("Shutdown w/ ret val of {0}", retVal));


Expand All @@ -314,6 +322,16 @@ public static int Main(string[] args)
return (retVal);
}

public void RecordTestRanCount()
Copy link
Member

Choose a reason for hiding this comment

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

NIT: The name RecordTestRunCount seems more apt.

{
StringBuilder sb = new();
foreach(var item in _testRanCounter)
Copy link
Contributor

Choose a reason for hiding this comment

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

When called via the CancelKeyPress event, the test will still be running while this code executes. Use _testRanCounterLock here.

{
sb.AppendLine($"{item.Key}: {item.Value}");
}
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, $"Tests ran count:\n{sb}");
Copy link
Member

Choose a reason for hiding this comment

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

NIT: Tests run* count.

}

public void HandleOom(Exception e, string message)
{
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.Tests, String.Format("Exception while running tests: {0}", e));
Expand Down Expand Up @@ -621,6 +639,11 @@ private void TestStarter()
DateTime lastStart = DateTime.Now; // keeps track of when we last started a test
TimeSpan minTimeToStartTest = new TimeSpan(0, 5, 0); // after 5 minutes if we haven't started a test we're having problems...
int cpuAdjust = 0, memAdjust = 0; // if we discover that we're not starting new tests quick enough we adjust the CPU/Mem percentages

foreach (var test in _curTestSet.Tests)
{
_testRanCounter[test.RefOrID] = 0;
}
// so we start new tests sooner (so they start BEFORE we drop below our minimum CPU)

//Console.WriteLine("RF - TestStarter found {0} tests to run", totalTestsToRun);
Expand Down Expand Up @@ -1196,6 +1219,16 @@ private void StartTestWorker(object test)
}
break;
}

lock (_testRanCounterLock)
{
string testRefOrID = daTest.RefOrID;
if (!_testRanCounter.Keys.Contains(testRefOrID))
{
_testRanCounter[testRefOrID] = 0;
}
_testRanCounter[testRefOrID] ++;
Copy link
Contributor

Choose a reason for hiding this comment

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

(purely a style comment)

You can use _testRanCounter[testRefOrId] = _testRanCounter.GetValueOrDefault(testRefOrId, 0) + 1

(you can even leave off the 0 and use the other GetValueOrDefault overload since 0 is the default value for uint)

}
}
catch (Exception e)
{
Expand Down