提交 930fd348 编写于 作者: S Sung Yoon Whang 提交者: GitHub

Test windows event log (dotnet/coreclr#17401)

* Windows Event Log tests

* Add test for windows event log

* Make it run under one executable

* Removing duplicate files

* remove more useless file

* fix formatting for reference to Diagnostics.EventLog

* Windows Event Log test is not supported outside Windows

* More logging to see why failures are occuring...

* Fix typo

* fix more typos

* just make the test pass on non-windows platforms

* Make the test more reliable with timing


Commit migrated from https://github.com/dotnet/coreclr/commit/e7c755118a97ed9cfb1b24a3c1e82007793fc227
上级 1227d9d7
......@@ -25,6 +25,9 @@
<PackageReference Include="System.Runtime.Intrinsics.Experimental">
<Version>$(MicrosoftPrivateCoreFxNETCoreAppPackageVersion)</Version>
</PackageReference>
<PackageReference Include="System.Diagnostics.EventLog">
<Version>$(MicrosoftPrivateCoreFxNETCoreAppPackageVersion)</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
......
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
class Program
{
private static void UnhandledException()
{
A();
}
private static void FailFast()
{
try
{
A();
}
catch (ArgumentException ex)
{
Environment.FailFast("failing fast", ex);
}
}
private static void A()
{
B();
}
private static void B()
{
throw new ArgumentException("my ae");
}
private static bool LaunchTest(string testName, string[] logEntriesToCheck)
{
DateTime dt = DateTime.Now;
Process testProcess = new Process();
string currentPath = Directory.GetCurrentDirectory();
string corerunPath = Environment.GetEnvironmentVariable("CORE_ROOT") + "\\corerun.exe";
testProcess.StartInfo.FileName = corerunPath;
testProcess.StartInfo.Arguments = currentPath + "\\WindowsEventLog.exe " + testName;
testProcess.StartInfo.EnvironmentVariables["CORE_ROOT"] = Environment.GetEnvironmentVariable("CORE_ROOT");
testProcess.StartInfo.UseShellExecute = false;
testProcess.Start();
testProcess.WaitForExit();
Thread.Sleep(2000);
EventLog log = new EventLog("Application");
foreach (EventLogEntry entry in log.Entries)
{
int checkCount = 0;
if (entry.TimeGenerated > dt)
{
String source = entry.Source;
String message = entry.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);
}
if (source.Contains(".NET Runtime") && checkCount == logEntriesToCheck.Length)
return true;
else if (source.Contains(".NET Runtime"))
{
Console.WriteLine("*** Event Log ***");
Console.WriteLine(message);
}
}
}
return false;
}
private static bool RunUnhandledExceptionTest()
{
string[] logEntriesToCheck = {"unhandled exception", "my ae", "ArgumentException"};
return LaunchTest("UnhandledException", logEntriesToCheck);
}
private static bool RunFailFastTest()
{
string[] logEntriesToCheck = {"The application requested process termination through System.Environment.FailFast(string message).", "failing fast", "ArgumentException"};
return LaunchTest("FailFast", logEntriesToCheck);
}
public static int Main(string[] args)
{
if (args.Length == 0) // When invoked with no args, launch itself with appropriate args to cause various exceptions
{
if (!System.Runtime.InteropServices.RuntimeInformation.OSDescription.Contains("Windows"))
{
return 100;
}
if (!RunUnhandledExceptionTest())
{
Console.WriteLine("WindowsEventLog Test: UnhandledExceptionTest failed.");
return 1;
}
if (!RunFailFastTest())
{
Console.WriteLine("WindowsEventLog Test: FailFastTest failed.");
return 1;
}
return 100;
}
Debug.Assert(args.Length == 1);
if (args[0] == "UnhandledException")
{
UnhandledException();
}
else if (args[0] == "FailFast")
{
FailFast();
}
return 100; // Should never reach here
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AssemblyName>WindowsEventLog</AssemblyName>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
<OutputType>Exe</OutputType>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<DefineConstants>$(DefineConstants);STATIC</DefineConstants>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
</PropertyGroup>
<PropertyGroup>
<DisableProjectBuild Condition="'$(TargetsUnix)' == 'true'">true</DisableProjectBuild>
</PropertyGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Diagnostics.EventLog" Version="4.5.0-preview1-26216-02" />
</ItemGroup>
<ItemGroup>
<Compile Include="WindowsEventLog.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
baseservices/exceptions/regressions/Dev11/147911/test147911/test147911.sh
baseservices/exceptions/regressions/V1/SEH/VJ/UnmanagedToManaged/UnmanagedToManaged.sh
baseservices/exceptions/WindowsEventLog/WindowsEventLog.sh
baseservices/threading/commitstackonlyasneeded/DefaultStackCommit/DefaultStackCommit.sh
baseservices/threading/interlocked/compareexchange/compareexchangetneg/compareexchangetneg.sh
baseservices/threading/monitor/pulse/monitorpulse02/monitorpulse02.sh
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册