Skip to content
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

[Merge-on-Red] - Implement XML log fixer for Helix #80751

Merged
merged 23 commits into from
Feb 14, 2023
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4686967
Temp log gets written as tests run, rather than just at the end.
ivdiazsa Dec 19, 2022
10747d9
Added placeholder for the XUnit log checker and it now builds with sr…
ivdiazsa Jan 7, 2023
2bc25fe
XUnit Log Checker is now functional in the repo. Next step is to bund…
ivdiazsa Jan 7, 2023
b628a21
Making progress in packaging to Helix.
ivdiazsa Jan 11, 2023
8bbacb6
Began adapting the log checker to the actual Helix context.
ivdiazsa Jan 12, 2023
786ed02
XML Fixer builds and works nowgit add *!
ivdiazsa Jan 14, 2023
e2e2a27
Forgot to replace the template with the actual values in helixpublish…
ivdiazsa Jan 17, 2023
1b991fc
Fixed a bug with unclosed quotes in the log checker
ivdiazsa Jan 19, 2023
01d9dcf
Fixed wrong log paths in Helix results.
ivdiazsa Jan 23, 2023
b550c77
Added missing Wasm logger stuff.
ivdiazsa Jan 24, 2023
e445e95
Updated and fixed merge conflicts with main.
ivdiazsa Jan 24, 2023
7c2753e
Fixed a mismatching tag in the log generator, that occurred when reco…
ivdiazsa Jan 24, 2023
9944bdb
Removed some messaging for dev-logging purposes, and fixed a problem …
ivdiazsa Jan 25, 2023
f344c31
Added missing stream writer for the temp log in the XHarnessRunner.
ivdiazsa Jan 26, 2023
13a9cb7
Added recorder of test counters.
ivdiazsa Jan 31, 2023
56febb3
Xml's and Csv's work fine now
ivdiazsa Feb 1, 2023
1e4d2c1
Merge branch 'main' into xml-regearing
Feb 6, 2023
45e2bd0
Began new approach...
ivdiazsa Feb 8, 2023
2651eb1
XUnitLogChecker should be functional now. Ready to move back from dra…
ivdiazsa Feb 9, 2023
4fa4599
Corrected changed signatures in the XHarnessTestRunner.
ivdiazsa Feb 9, 2023
b7e44b7
Fixed a couple issues with browser-wasm generated XHarness test runners.
ivdiazsa Feb 10, 2023
f342ede
Attempt to fix Browser-Wasm's weird way of layoutting tests.
ivdiazsa Feb 10, 2023
ec5aef0
Browser-Wasm is not possible to implement right here. Removing it...
ivdiazsa Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
XUnit Log Checker is now functional in the repo. Next step is to bund…
…le it and have Helix use it as needed.
  • Loading branch information
ivdiazsa committed Jan 7, 2023
commit 2bc25fe5aaf5c731663611f709856abb8a01d92b
77 changes: 70 additions & 7 deletions src/tests/Common/XUnitLogChecker/XUnitLogChecker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

public class XUnitLogChecker
Expand All @@ -10,18 +13,24 @@ private static class Patterns
public const string CloseTag = @"(\B</\w+>)|(\]\]>)";
}

const int SUCCESS = 0;
const int FAILURE = -1;

static int Main(string[] args)
{
if (args.Count() < 1)
{
Console.WriteLine("The path to the XML log file to be checked is required.");
return -1;
}

// Check if the XUnit log is well-formed. If yes, then we have nothing
// else to do :)
if (TryLoadXml(args[0]))
{
Console.WriteLine($"The given XML '{args[0]}' is well formed! Exiting...");
return SUCCESS;
return 0;
}

return FAILURE;
FixTheXml(args[0]);
return 0;
}

static bool TryLoadXml(string xFile)
Expand All @@ -34,14 +43,68 @@ static bool TryLoadXml(string xFile)
xDocument.Load(xReader);
}
}

catch (Exception ex)
{
Console.WriteLine($"The given XML {xFile} was malformed. Fixing now...");
return false;
}

return true;
}

static void FixTheXml(string xFile)
{
var tags = new Stack<string>();

foreach (string line in File.ReadLines(xFile))
{
// Get all XML tags found in the current line.
var opens = Regex.Matches(line, Patterns.OpenTag).ToList();
var closes = Regex.Matches(line, Patterns.CloseTag).ToList();

foreach (Match m in opens)
{
// Push the next opening tag to the stack. We need only the actual
// tag without the opening and closing symbols, so we ask LINQ to
// lend us a hand.
tags.Push(new String(m.Value.Where(c => char.IsLetter(c)).ToArray()));
}

// If we found any closing tags, then ensure they match their respective
// opening ones before continuing the analysis.
while (closes.Count > 0)
{
string nextClosing = closes.First().Value.Equals("]]>")
? "CDATA"
: new String(closes.First()
.Value
.Where(c => char.IsLetter(c))
.ToArray());

if (nextClosing.Equals(tags.Peek()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we flush all writes to the xUnit log? Otherwise a crash may end up with an incomplete log finishing with a partial close tag mismatching the corresponding open tag - I guess we may be able to work around it but I suspect it would require a more precise XML scanner - I leave it up to you and Jeremy to decide whether it's worth it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that would be an issue. For example, let's suppose we are running Methodical_d1.sh. If I click Ctrl-C midrun, it literally stops logging right then and there, so I don't think we would end up with this mismatching example.

{
tags.Pop();
closes.RemoveAt(0);
}
}
}

if (tags.Count == 0)
{
Console.WriteLine($"\nXUnit log file '{xFile}' was A-OK!\n");
}

// Write the closings for all the lone opened tags we found.
using (StreamWriter xsw = File.AppendText(xFile))
while (tags.Count > 0)
{
string tag = tags.Pop();
if (tag.Equals("CDATA"))
xsw.WriteLine("]]>");
else
xsw.WriteLine($"</{tag}>");
}

Console.WriteLine("\nXUnit log file has been fixed!\n");
}
}