- Notifications
You must be signed in to change notification settings - Fork 5.2k
Bootstrapping a test for R2RDump #42150
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Runtime.InteropServices; | ||
| using Xunit; | ||
| | ||
| namespace R2RDumpTests | ||
| { | ||
| public class R2RDumpTester : XunitBase | ||
| { | ||
| private const string CoreRoot = "CORE_ROOT"; | ||
| private const string R2RDumpRelativePath = "R2RDump"; | ||
| private const string R2RDumpFile = "R2RDump.dll"; | ||
| private const string CoreRunFileName = "corerun"; | ||
| | ||
| public static string FindExePath(string exe) | ||
| { | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| exe = exe + ".exe"; | ||
| } | ||
| exe = Environment.ExpandEnvironmentVariables(exe); | ||
| if (!File.Exists(exe)) | ||
| { | ||
| if (Path.GetDirectoryName(exe) == String.Empty) | ||
| { | ||
| foreach (string test in (Environment.GetEnvironmentVariable("PATH") ?? "").Split(Path.PathSeparator)) | ||
| { | ||
| string path = test.Trim(); | ||
| if (!String.IsNullOrEmpty(path) && File.Exists(path = Path.Combine(path, exe))) | ||
| return Path.GetFullPath(path); | ||
| } | ||
| } | ||
| throw new FileNotFoundException(new FileNotFoundException().Message, exe); | ||
| } | ||
| return Path.GetFullPath(exe); | ||
| } | ||
| | ||
| [Fact] | ||
| public void DumpCoreLib() | ||
| { | ||
| string CoreRootVar = Environment.GetEnvironmentVariable(CoreRoot); | ||
| bool IsUnix = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows); | ||
| string R2RDumpAbsolutePath = Path.Combine(CoreRootVar, R2RDumpRelativePath, R2RDumpFile); | ||
| string CoreLibFile = "System.Private.CoreLib.dll"; | ||
| string CoreLibAbsolutePath = Path.Combine(CoreRootVar, CoreLibFile); | ||
| string OutputFile = Path.GetTempFileName(); | ||
| string TestDotNetCmdVar = Environment.GetEnvironmentVariable("__TestDotNetCmd"); | ||
| string DotNetAbsolutePath = string.IsNullOrEmpty(TestDotNetCmdVar) ? FindExePath("dotnet") : TestDotNetCmdVar; | ||
| | ||
| ProcessStartInfo processStartInfo = new ProcessStartInfo | ||
| { | ||
| UseShellExecute = false, | ||
| FileName = DotNetAbsolutePath, | ||
| // TODO, what flags do we like to test? | ||
| ||
| Arguments = string.Join(" ", new string[]{"exec", R2RDumpAbsolutePath, "--in", CoreLibAbsolutePath, "--out", OutputFile}) | ||
| }; | ||
| | ||
| Process process = Process.Start(processStartInfo); | ||
| process.WaitForExit(); | ||
| int exitCode = process.ExitCode; | ||
| string outputContent = File.ReadAllText(OutputFile); | ||
| File.Delete(OutputFile); | ||
| // TODO, here is a point where we can add more validation to outputs | ||
| // An uncaught exception (such as signature decoding error, would be caught by the error code) | ||
| bool failed = exitCode != 0; | ||
| if (failed) | ||
| { | ||
| Console.WriteLine("The process terminated with exit code {0}", exitCode); | ||
| Console.WriteLine(outputContent); | ||
| Assert.True(!failed); | ||
| } | ||
| } | ||
| | ||
| public static int Main(string[] args) | ||
| { | ||
| return new R2RDumpTester().RunTests(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <DisableProjectBuild Condition="'$(RuntimeFlavor)' != 'coreclr'">true</DisableProjectBuild> | ||
| <CLRTestTargetUnsupported Condition="'$(RuntimeFlavor)' != 'coreclr'">true</CLRTestTargetUnsupported> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="R2RDumpTester.cs" /> | ||
| <Compile Include="..\Common\XunitBase.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Remove="Resources\**" /> | ||
| <EmbeddedResource Remove="Resources\**" /> | ||
| <None Remove="Resources\**" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="xunit" Version="$(XUnitVersion)" /> | ||
| </ItemGroup> | ||
| </Project> |
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.