Skip to content

Commit 375b3dd

Browse files
committed
Code review feedback
1 parent 83e9a82 commit 375b3dd

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

src/tests/issues.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,5 +3338,8 @@
33383338
<ExcludeList Include = "$(XunitTestBinBase)/GC/Scenarios/ServerModel/servermodel/*">
33393339
<Issue>Use more memory than the emulator on helix machine allows</Issue>
33403340
</ExcludeList>
3341+
<ExcludeList Include = "$(XunitTestBinBase)/r2rdump/*">
3342+
<Issue>These tests are not supposed to be run with mono.</Issue>
3343+
</ExcludeList>
33413344
</ItemGroup>
33423345
</Project>

src/tests/r2rdump/R2RDumpTester.cs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,64 @@ public class R2RDumpTester : XunitBase
1212
private const string R2RDumpRelativePath = "R2RDump";
1313
private const string R2RDumpFile = "R2RDump.dll";
1414
private const string CoreRunFileName = "corerun";
15+
16+
public static string FindExePath(string exe)
17+
{
18+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
19+
{
20+
exe = exe + ".exe";
21+
}
22+
exe = Environment.ExpandEnvironmentVariables(exe);
23+
if (!File.Exists(exe))
24+
{
25+
if (Path.GetDirectoryName(exe) == String.Empty)
26+
{
27+
foreach (string test in (Environment.GetEnvironmentVariable("PATH") ?? "").Split(Path.PathSeparator))
28+
{
29+
string path = test.Trim();
30+
if (!String.IsNullOrEmpty(path) && File.Exists(path = Path.Combine(path, exe)))
31+
return Path.GetFullPath(path);
32+
}
33+
}
34+
throw new FileNotFoundException(new FileNotFoundException().Message, exe);
35+
}
36+
return Path.GetFullPath(exe);
37+
}
1538

1639
[Fact]
1740
public void DumpCoreLib()
1841
{
1942
string CoreRootVar = Environment.GetEnvironmentVariable(CoreRoot);
2043
bool IsUnix = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
21-
string CoreRunFile = CoreRunFileName + (IsUnix ? string.Empty : ".exe");
22-
string CoreRunAbsolutePath = Path.Combine(CoreRootVar, CoreRunFile);
23-
string R2RDumpAbsolutePath = Path.Combine(Path.Combine(CoreRootVar, R2RDumpRelativePath), R2RDumpFile);
44+
string R2RDumpAbsolutePath = Path.Combine(CoreRootVar, R2RDumpRelativePath, R2RDumpFile);
2445
string CoreLibFile = "System.Private.CoreLib.dll";
2546
string CoreLibAbsolutePath = Path.Combine(CoreRootVar, CoreLibFile);
2647
string OutputFile = Path.GetTempFileName();
48+
string TestDotNetCmdVar = Environment.GetEnvironmentVariable("__TestDotNetCmd");
49+
string DotNetAbsolutePath = string.IsNullOrEmpty(TestDotNetCmdVar) ? FindExePath("dotnet") : TestDotNetCmdVar;
2750

2851
ProcessStartInfo processStartInfo = new ProcessStartInfo
2952
{
3053
UseShellExecute = false,
31-
FileName = CoreRunAbsolutePath,
54+
FileName = DotNetAbsolutePath,
3255
// TODO, what flags do we like to test?
33-
Arguments = string.Join(" ", new string[]{R2RDumpAbsolutePath, "--in", CoreLibAbsolutePath, "--out", OutputFile})
56+
Arguments = string.Join(" ", new string[]{"exec", R2RDumpAbsolutePath, "--in", CoreLibAbsolutePath, "--out", OutputFile})
3457
};
3558

3659
Process process = Process.Start(processStartInfo);
3760
process.WaitForExit();
38-
string outputFileContent = File.ReadAllText(OutputFile);
39-
// TODO, validate content more carefully
40-
Assert.True(outputFileContent.Contains("ToString"));
61+
int exitCode = process.ExitCode;
62+
string outputContent = File.ReadAllText(OutputFile);
4163
File.Delete(OutputFile);
64+
// TODO, here is a point where we can add more validation to outputs
65+
// An uncaught exception (such as signature decoding error, would be caught by the error code)
66+
bool failed = exitCode != 0;
67+
if (failed)
68+
{
69+
Console.WriteLine("The process terminated with exit code {0}", exitCode);
70+
Console.WriteLine(outputContent);
71+
Assert.True(!failed);
72+
}
4273
}
4374

4475
public static int Main(string[] args)

src/tests/r2rdump/R2RDumpTests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4+
<DisableProjectBuild Condition="'$(RuntimeFlavor)' != 'coreclr'">true</DisableProjectBuild>
5+
<CLRTestTargetUnsupported Condition="'$(RuntimeFlavor)' != 'coreclr'">true</CLRTestTargetUnsupported>
46
</PropertyGroup>
57
<ItemGroup>
68
<Compile Include="R2RDumpTester.cs" />

0 commit comments

Comments
 (0)