forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the ReadyToRun.SuperIlc tool to CoreCLR
After Michal moved the Crossgen2 compiler source code to CoreCLR, this testing tool is the last bit that only exists in CoreRT so I'm moving it too. This initial commit amounts to a straightforward copy of SuperIlc source code from the CoreRT repo. Thanks Tomas Commit migrated from dotnet/coreclr@5f04a3d
- Loading branch information
1 parent
f46f06c
commit 77b7422
Showing
23 changed files
with
4,653 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,185 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace ReadyToRun.SuperIlc | ||
{ | ||
public class Buckets | ||
{ | ||
private Dictionary<string, List<ProcessInfo>> _bucketMap; | ||
|
||
public Buckets() | ||
{ | ||
_bucketMap = new Dictionary<string, List<ProcessInfo>>(StringComparer.OrdinalIgnoreCase); | ||
} | ||
|
||
public void AddCompilation(ProcessInfo process) => Add(AnalyzeCompilationFailure(process), process); | ||
public void AddExecution(ProcessInfo process) => Add(AnalyzeExecutionFailure(process), process); | ||
|
||
public void Add(string bucket, ProcessInfo process) | ||
{ | ||
List<ProcessInfo> processes; | ||
if (!_bucketMap.TryGetValue(bucket, out processes)) | ||
{ | ||
processes = new List<ProcessInfo>(); | ||
_bucketMap.Add(bucket, processes); | ||
} | ||
processes.Add(process); | ||
} | ||
|
||
public void WriteToFile(string outputFile, bool detailed) | ||
{ | ||
using (StreamWriter outputStream = new StreamWriter(outputFile)) | ||
{ | ||
WriteToStream(outputStream, detailed); | ||
} | ||
} | ||
|
||
public void WriteToStream(StreamWriter output, bool detailed) | ||
{ | ||
output.WriteLine($@"#buckets: {_bucketMap.Count}, #failures: {_bucketMap.Sum(b => b.Value.Count)}"); | ||
|
||
if (_bucketMap.Count == 0) | ||
{ | ||
// No bucketing info to display | ||
return; | ||
} | ||
|
||
IEnumerable<KeyValuePair<string, List<ProcessInfo>>> orderedBuckets = _bucketMap.OrderByDescending(bucket => bucket.Value.Count); | ||
foreach (KeyValuePair<string, List<ProcessInfo>> bucketKvp in orderedBuckets) | ||
{ | ||
bucketKvp.Value.Sort((a, b) => a.Parameters.InputFileName.CompareTo(b.Parameters.InputFileName)); | ||
output.WriteLine($@" [{bucketKvp.Value.Count} failures] {bucketKvp.Key}"); | ||
} | ||
|
||
output.WriteLine(); | ||
output.WriteLine("Detailed bucket info:"); | ||
|
||
foreach (KeyValuePair<string, List<ProcessInfo>> bucketKvp in orderedBuckets) | ||
{ | ||
output.WriteLine(""); | ||
output.WriteLine($@"Bucket name: {bucketKvp.Key}"); | ||
output.WriteLine($@"Failing tests ({bucketKvp.Value.Count} total):"); | ||
|
||
foreach (ProcessInfo failure in bucketKvp.Value) | ||
{ | ||
output.WriteLine($@" {failure.Parameters.InputFileName}"); | ||
} | ||
|
||
if (detailed) | ||
{ | ||
output.WriteLine(); | ||
output.WriteLine($@"Detailed test failures:"); | ||
|
||
foreach (ProcessInfo failure in bucketKvp.Value) | ||
{ | ||
output.WriteLine($@"Test: {failure.Parameters.InputFileName}"); | ||
try | ||
{ | ||
output.WriteLine(File.ReadAllText(failure.Parameters.LogPath)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
output.WriteLine($"Error reading file {failure.Parameters.LogPath}: {ex.Message}"); | ||
} | ||
output.WriteLine(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static string AnalyzeCompilationFailure(ProcessInfo process) | ||
{ | ||
try | ||
{ | ||
if (process.TimedOut) | ||
{ | ||
return "Timed out"; | ||
} | ||
|
||
string[] lines = File.ReadAllLines(process.Parameters.LogPath); | ||
|
||
for (int lineIndex = 2; lineIndex < lines.Length; lineIndex++) | ||
{ | ||
string line = lines[lineIndex]; | ||
if (line.Length == 0 || | ||
line.StartsWith("EXEC : warning") || | ||
line.StartsWith("To repro,") || | ||
line.StartsWith("Emitting R2R PE file") || | ||
line.StartsWith("Warning: ") || | ||
line.StartsWith("Info: ") || | ||
line == "Assertion Failed") | ||
{ | ||
continue; | ||
} | ||
return line; | ||
} | ||
return string.Join("; ", lines); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ex.Message; | ||
} | ||
} | ||
|
||
private static string AnalyzeExecutionFailure(ProcessInfo process) | ||
{ | ||
try | ||
{ | ||
if (process.TimedOut) | ||
{ | ||
return "Timed out"; | ||
} | ||
|
||
string[] lines = File.ReadAllLines(process.Parameters.LogPath); | ||
|
||
for (int lineIndex = 0; lineIndex < lines.Length; lineIndex++) | ||
{ | ||
string line = lines[lineIndex]; | ||
if (line.StartsWith("Assert failure")) | ||
{ | ||
int openParen = line.IndexOf('('); | ||
int closeParen = line.IndexOf(')', openParen + 1); | ||
if (openParen > 0 && closeParen > openParen) | ||
{ | ||
line = line.Substring(0, openParen) + line.Substring(closeParen + 1); | ||
} | ||
return line; | ||
} | ||
else if (line.StartsWith("Unhandled exception", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
int leftBracket = line.IndexOf('['); | ||
int rightBracket = line.IndexOf(']', leftBracket + 1); | ||
if (leftBracket >= 0 && rightBracket > leftBracket) | ||
{ | ||
line = line.Substring(0, leftBracket) + line.Substring(rightBracket + 1); | ||
} | ||
for (int detailLineIndex = lineIndex + 1; detailLineIndex < lines.Length; detailLineIndex++) | ||
{ | ||
string detailLine = lines[detailLineIndex].TrimStart(); | ||
if (!detailLine.StartsWith("--->")) | ||
{ | ||
break; | ||
} | ||
line += " " + detailLine; | ||
} | ||
return line; | ||
} | ||
} | ||
|
||
return $"Exit code: {process.ExitCode} = 0x{process.ExitCode:X8}, expected {process.Parameters.ExpectedExitCode}"; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ex.Message; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.