summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSteve MacLean <stmaclea@microsoft.com>2019-03-27 17:24:00 -0400
committerGitHub <noreply@github.com>2019-03-27 17:24:00 -0400
commit66c05cea421a9f388eaebece2b9e64ce4560c5c5 (patch)
tree4ba14774b9e34a64559f193d797b7628116b0239 /tests
parentc3e1bd5ccc482c9a7670762676bda95ebd34707d (diff)
downloadcoreclr-66c05cea421a9f388eaebece2b9e64ce4560c5c5.tar.gz
coreclr-66c05cea421a9f388eaebece2b9e64ce4560c5c5.tar.bz2
coreclr-66c05cea421a9f388eaebece2b9e64ce4560c5c5.zip
Extend WindowsEventLog test for EntryPointFilter (#23178)
* Extend WindowsEventLog test Verify EntryPointFilter solves logging problem with native host swallowing exceptions WindowsEventLog only look at new entries WindowsEventLog remove time check Add mechanism to corhost to emulate host swallowing all exceptions * PR feedback
Diffstat (limited to 'tests')
-rw-r--r--tests/src/baseservices/exceptions/WindowsEventLog/WindowsEventLog.cs59
1 files changed, 40 insertions, 19 deletions
diff --git a/tests/src/baseservices/exceptions/WindowsEventLog/WindowsEventLog.cs b/tests/src/baseservices/exceptions/WindowsEventLog/WindowsEventLog.cs
index d4fd9292aa..7d83bd4e4d 100644
--- a/tests/src/baseservices/exceptions/WindowsEventLog/WindowsEventLog.cs
+++ b/tests/src/baseservices/exceptions/WindowsEventLog/WindowsEventLog.cs
@@ -50,13 +50,11 @@ class Program
.Select(s => s[random.Next(s.Length)]).ToArray());
}
- private static bool LaunchTest(string testName, string[] logEntriesToCheck, string randomCookie)
+ private static bool LaunchTest(string testName, string[] logEntriesToCheck, string randomCookie, bool swallowExcep = false, bool useEntryPointFilter = false)
{
EventLog logBefore = new EventLog("Application");
int logBeforeCount = logBefore.Entries.Count;
- DateTime dt = DateTime.Now;
-
Process testProcess = new Process();
string currentPath = Directory.GetCurrentDirectory();
string corerunPath = Environment.GetEnvironmentVariable("CORE_ROOT") + "\\corerun.exe";
@@ -64,6 +62,8 @@ class Program
testProcess.StartInfo.FileName = corerunPath;
testProcess.StartInfo.Arguments = currentPath + "\\WindowsEventLog.exe " + testName + " " + randomCookie;
testProcess.StartInfo.EnvironmentVariables["CORE_ROOT"] = Environment.GetEnvironmentVariable("CORE_ROOT");
+ testProcess.StartInfo.EnvironmentVariables["COMPlus_Corhost_Swallow_Uncaught_Exceptions"] = swallowExcep ? "1" : "0";
+ testProcess.StartInfo.EnvironmentVariables["COMPlus_UseEntryPointFilter"] = useEntryPointFilter ? "1" : "0";
testProcess.StartInfo.UseShellExecute = false;
testProcess.Start();
@@ -75,32 +75,31 @@ class Program
Console.WriteLine("Found {0} entries in Event Log", logAfter.Entries.Count);
- foreach (EventLogEntry entry in logAfter.Entries)
+ for (int i = logAfter.Entries.Count - 1; i >= logBeforeCount; --i)
{
+ EventLogEntry entry = logAfter.Entries[i];
int checkCount = 0;
- if (entry.TimeGenerated > dt.AddMinutes(-3)) // Grant some leeway in the time error was logged
- {
- String source = entry.Source;
- String message = entry.Message;
+ String source = entry.Source;
+ String message = entry.Message;
+
+ if (source.Contains(".NET Runtime"))
+ {
+ Console.WriteLine("*** Event Log ***");
+ Console.WriteLine(message);
foreach (string logEntry in logEntriesToCheck)
{
Console.WriteLine("Checking for existence of : " + logEntry);
if (message.Contains(logEntry))
checkCount += 1;
else
- Console.WriteLine("Couldn't find it in: " + message);
+ Console.WriteLine("!!! Couldn't find it !!!");
}
- if (source.Contains(".NET Runtime") && checkCount == logEntriesToCheck.Length && logBeforeCount < logAfter.Entries.Count)
+ if (checkCount == logEntriesToCheck.Length)
{
return true;
}
- else if (source.Contains(".NET Runtime"))
- {
- Console.WriteLine("*** Event Log ***");
- Console.WriteLine(message);
- }
}
}
return false;
@@ -117,11 +116,11 @@ class Program
}
#endif
- private static bool RunUnhandledExceptionTest()
+ private static bool RunUnhandledExceptionTest(bool swallowExcep = false, bool useEntryPointFilter = false)
{
string cookie = RandomCookie();
string[] logEntriesToCheck = { "unhandled exception", "ArgumentException", cookie };
- return LaunchTest("UnhandledException", logEntriesToCheck, cookie);
+ return LaunchTest("UnhandledException", logEntriesToCheck, cookie, swallowExcep, useEntryPointFilter);
}
private static bool RunFailFastTest()
@@ -131,7 +130,6 @@ class Program
return LaunchTest("FailFast", logEntriesToCheck, cookie);
}
-
public static int Main(string[] args)
{
if (args.Length == 0) // When invoked with no args, launch itself with appropriate args to cause various exceptions
@@ -144,7 +142,30 @@ class Program
if (!RunUnhandledExceptionTest())
{
- Console.WriteLine("WindowsEventLog Test: UnhandledExceptionTest failed.");
+ Console.WriteLine("WindowsEventLog Test: UnhandledExceptionTest() failed.");
+ return 1;
+ }
+
+ if (RunUnhandledExceptionTest(swallowExcep:true))
+ {
+ // Swallowing exceptions is reported to prevent logging to the Windows log.
+ // This is more of a test configuration sanity check than a requirement
+ Console.WriteLine("WindowsEventLog Test: UnhandledExceptionTest(swallowExcep:true) should have failed.");
+ return 1;
+ }
+
+ if (!RunUnhandledExceptionTest(swallowExcep:true, useEntryPointFilter:true))
+ {
+ // Logging should be the same with useEntryPointFilter
+ Console.WriteLine("WindowsEventLog Test: UnhandledExceptionTest(swallowExcep:true, useEntryPointFilter:true) failed.");
+ return 1;
+ }
+
+ if (!RunUnhandledExceptionTest(swallowExcep:false, useEntryPointFilter:true))
+ {
+ // Logging should be the same with useEntryPointFilter even without swallowing exception handler
+ // This is more of a test configuration sanity check than a requirement
+ Console.WriteLine("WindowsEventLog Test: UnhandledExceptionTest(swallowExcep:false, useEntryPointFilter:true) failed.");
return 1;
}