Merge pull request #3497 from sfc-gh-kmakino/kaomakino/testharness_json_support
Add JSON trace support in TestHarness (Take 2)
This commit is contained in:
commit
97b8c43b86
|
@ -3,7 +3,7 @@ set(SRCS
|
||||||
Properties/AssemblyInfo.cs)
|
Properties/AssemblyInfo.cs)
|
||||||
|
|
||||||
set(TEST_HARNESS_REFERENCES
|
set(TEST_HARNESS_REFERENCES
|
||||||
"-r:System,System.Core,System.Xml.Linq,System.Data.DataSetExtensions,Microsoft.CSharp,System.Data,System.Xml,${TraceLogHelperDll}")
|
"-r:System,System.Core,System.Xml.Linq,System.Data.DataSetExtensions,Microsoft.CSharp,System.Data,System.Xml,System.Runtime.Serialization,${TraceLogHelperDll}")
|
||||||
|
|
||||||
set(out_file ${CMAKE_BINARY_DIR}/packages/bin/TestHarness.exe)
|
set(out_file ${CMAKE_BINARY_DIR}/packages/bin/TestHarness.exe)
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ using System.Diagnostics;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using System.Runtime.Serialization.Json;
|
||||||
|
|
||||||
namespace SummarizeTest
|
namespace SummarizeTest
|
||||||
{
|
{
|
||||||
|
@ -362,20 +363,22 @@ namespace SummarizeTest
|
||||||
{
|
{
|
||||||
ErrorOutputListener errorListener = new ErrorOutputListener();
|
ErrorOutputListener errorListener = new ErrorOutputListener();
|
||||||
process.StartInfo.UseShellExecute = false;
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
string tlsPluginArg = "";
|
||||||
if (tlsPluginFile.Length > 0) {
|
if (tlsPluginFile.Length > 0) {
|
||||||
process.StartInfo.EnvironmentVariables["FDB_TLS_PLUGIN"] = tlsPluginFile;
|
process.StartInfo.EnvironmentVariables["FDB_TLS_PLUGIN"] = tlsPluginFile;
|
||||||
|
tlsPluginArg = "--tls_plugin=" + tlsPluginFile;
|
||||||
}
|
}
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
var args = "";
|
var args = "";
|
||||||
if (willRestart && oldBinaryName.EndsWith("alpha6"))
|
if (willRestart && oldBinaryName.EndsWith("alpha6"))
|
||||||
{
|
{
|
||||||
args = string.Format("-Rs 1000000000 -r simulation {0} -s {1} -f \"{2}\" -b {3} --tls_plugin={4} --crash",
|
args = string.Format("-Rs 1000000000 -r simulation {0} -s {1} -f \"{2}\" -b {3} {4} --crash",
|
||||||
IsRunningOnMono() ? "" : "-q", seed, testFile, buggify ? "on" : "off", tlsPluginFile);
|
IsRunningOnMono() ? "" : "-q", seed, testFile, buggify ? "on" : "off", tlsPluginArg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args = string.Format("-Rs 1GB -r simulation {0} -s {1} -f \"{2}\" -b {3} --tls_plugin={4} --crash",
|
args = string.Format("-Rs 1GB -r simulation {0} -s {1} -f \"{2}\" -b {3} {4} --crash",
|
||||||
IsRunningOnMono() ? "" : "-q", seed, testFile, buggify ? "on" : "off", tlsPluginFile);
|
IsRunningOnMono() ? "" : "-q", seed, testFile, buggify ? "on" : "off", tlsPluginArg);
|
||||||
}
|
}
|
||||||
if (restarting) args = args + " --restarting";
|
if (restarting) args = args + " --restarting";
|
||||||
if (useValgrind && !willRestart)
|
if (useValgrind && !willRestart)
|
||||||
|
@ -480,7 +483,7 @@ namespace SummarizeTest
|
||||||
memCheckThread.Join();
|
memCheckThread.Join();
|
||||||
consoleThread.Join();
|
consoleThread.Join();
|
||||||
|
|
||||||
var traceFiles = Directory.GetFiles(tempPath, "trace*.xml");
|
var traceFiles = Directory.GetFiles(tempPath, "trace*.*").Where(s => s.EndsWith(".xml") || s.EndsWith(".json")).ToArray();
|
||||||
if (traceFiles.Length == 0)
|
if (traceFiles.Length == 0)
|
||||||
{
|
{
|
||||||
if (!traceToStdout)
|
if (!traceToStdout)
|
||||||
|
@ -661,6 +664,10 @@ namespace SummarizeTest
|
||||||
return whats.ToArray();
|
return whats.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delegate IEnumerable<Magnesium.Event> parseDelegate(System.IO.Stream stream, string file,
|
||||||
|
bool keepOriginalElement = false, double startTime = -1, double endTime = Double.MaxValue,
|
||||||
|
double samplingFactor = 1.0);
|
||||||
|
|
||||||
static int Summarize(string[] traceFiles, string summaryFileName,
|
static int Summarize(string[] traceFiles, string summaryFileName,
|
||||||
string errorFileName, bool? killed, List<string> outputErrors, int? exitCode, long? peakMemory,
|
string errorFileName, bool? killed, List<string> outputErrors, int? exitCode, long? peakMemory,
|
||||||
string uid, string valgrindOutputFileName, int expectedUnseed, out int unseed, out bool retryableError, bool logOnRetryableError,
|
string uid, string valgrindOutputFileName, int expectedUnseed, out int unseed, out bool retryableError, bool logOnRetryableError,
|
||||||
|
@ -692,7 +699,12 @@ namespace SummarizeTest
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var ev in Magnesium.XmlParser.Parse(traceFile, traceFileName))
|
parseDelegate parse;
|
||||||
|
if (traceFileName.EndsWith(".json"))
|
||||||
|
parse = Magnesium.JsonParser.Parse;
|
||||||
|
else
|
||||||
|
parse = Magnesium.XmlParser.Parse;
|
||||||
|
foreach (var ev in parse(traceFile, traceFileName))
|
||||||
{
|
{
|
||||||
Magnesium.Severity newSeverity;
|
Magnesium.Severity newSeverity;
|
||||||
if (severityMap.TryGetValue(new KeyValuePair<string, Magnesium.Severity>(ev.Type, ev.Severity), out newSeverity))
|
if (severityMap.TryGetValue(new KeyValuePair<string, Magnesium.Severity>(ev.Type, ev.Severity), out newSeverity))
|
||||||
|
@ -1092,10 +1104,20 @@ namespace SummarizeTest
|
||||||
|
|
||||||
private static void AppendToSummary(string summaryFileName, XElement xout, bool traceToStdout = false, bool shouldLock = true)
|
private static void AppendToSummary(string summaryFileName, XElement xout, bool traceToStdout = false, bool shouldLock = true)
|
||||||
{
|
{
|
||||||
|
bool useXml = true;
|
||||||
|
if (summaryFileName != null && summaryFileName.EndsWith(".json")) {
|
||||||
|
useXml = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (traceToStdout)
|
if (traceToStdout)
|
||||||
{
|
{
|
||||||
using (var wr = System.Xml.XmlWriter.Create(Console.OpenStandardOutput(), new System.Xml.XmlWriterSettings() { OmitXmlDeclaration = true, Encoding = new System.Text.UTF8Encoding(false) }))
|
if (useXml) {
|
||||||
xout.WriteTo(wr);
|
using (var wr = System.Xml.XmlWriter.Create(Console.OpenStandardOutput(), new System.Xml.XmlWriterSettings() { OmitXmlDeclaration = true, Encoding = new System.Text.UTF8Encoding(false) }))
|
||||||
|
xout.WriteTo(wr);
|
||||||
|
} else {
|
||||||
|
using (var wr = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonWriter(Console.OpenStandardOutput()))
|
||||||
|
xout.WriteTo(wr);
|
||||||
|
}
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1106,7 +1128,6 @@ namespace SummarizeTest
|
||||||
takeLock(summaryFileName);
|
takeLock(summaryFileName);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
using (var f = System.IO.File.Open(summaryFileName, System.IO.FileMode.Append, System.IO.FileAccess.Write))
|
using (var f = System.IO.File.Open(summaryFileName, System.IO.FileMode.Append, System.IO.FileAccess.Write))
|
||||||
{
|
{
|
||||||
if (f.Length == 0)
|
if (f.Length == 0)
|
||||||
|
@ -1114,8 +1135,13 @@ namespace SummarizeTest
|
||||||
byte[] bytes = Encoding.UTF8.GetBytes("<Trace>");
|
byte[] bytes = Encoding.UTF8.GetBytes("<Trace>");
|
||||||
f.Write(bytes, 0, bytes.Length);
|
f.Write(bytes, 0, bytes.Length);
|
||||||
}
|
}
|
||||||
using (var wr = System.Xml.XmlWriter.Create(f, new System.Xml.XmlWriterSettings() { OmitXmlDeclaration = true }))
|
if (useXml) {
|
||||||
xout.Save(wr);
|
using (var wr = System.Xml.XmlWriter.Create(f, new System.Xml.XmlWriterSettings() { OmitXmlDeclaration = true }))
|
||||||
|
xout.Save(wr);
|
||||||
|
} else {
|
||||||
|
using (var wr = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonWriter(f))
|
||||||
|
xout.WriteTo(wr);
|
||||||
|
}
|
||||||
var endl = Encoding.UTF8.GetBytes(Environment.NewLine);
|
var endl = Encoding.UTF8.GetBytes(Environment.NewLine);
|
||||||
f.Write(endl, 0, endl.Length);
|
f.Write(endl, 0, endl.Length);
|
||||||
}
|
}
|
||||||
|
@ -1126,6 +1152,7 @@ namespace SummarizeTest
|
||||||
releaseLock(summaryFileName);
|
releaseLock(summaryFileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AppendXmlMessageToSummary(string summaryFileName, XElement xout, bool traceToStdout = false, string testFile = null,
|
private static void AppendXmlMessageToSummary(string summaryFileName, XElement xout, bool traceToStdout = false, string testFile = null,
|
||||||
int? seed = null, bool? buggify = null, bool? determinismCheck = null, string oldBinaryName = null)
|
int? seed = null, bool? buggify = null, bool? determinismCheck = null, string oldBinaryName = null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace Magnesium
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Failed to parse {0}", root), e);
|
throw new Exception(string.Format("Failed to parse JSON {0}", root), e);
|
||||||
}
|
}
|
||||||
if (ev != null) yield return ev;
|
if (ev != null) yield return ev;
|
||||||
}
|
}
|
||||||
|
@ -80,8 +80,9 @@ namespace Magnesium
|
||||||
TraceFile = file,
|
TraceFile = file,
|
||||||
DDetails = xEvent.Elements()
|
DDetails = xEvent.Elements()
|
||||||
.Where(a=>a.Name != "Type" && a.Name != "Time" && a.Name != "Machine" && a.Name != "ID" && a.Name != "Severity" && (!rolledEvent || a.Name != "OriginalTime"))
|
.Where(a=>a.Name != "Type" && a.Name != "Time" && a.Name != "Machine" && a.Name != "ID" && a.Name != "Severity" && (!rolledEvent || a.Name != "OriginalTime"))
|
||||||
.ToDictionary(a=>string.Intern(a.Name.LocalName), a=>(object)a.Value),
|
// When the key contains a colon character, it gets parsed as a:item
|
||||||
original = keepOriginalElement ? xEvent : null,
|
.ToDictionary(a=>a.Name.LocalName == "item" ? a.Attribute("item").Value : string.Intern(a.Name.LocalName), a=>(object)a.Value),
|
||||||
|
original = keepOriginalElement ? xEvent : null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace Magnesium
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Failed to parse {0}", xev), e);
|
throw new Exception(string.Format("Failed to parse XML {0}", xev), e);
|
||||||
}
|
}
|
||||||
if (ev != null) yield return ev;
|
if (ev != null) yield return ev;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue