Skip to content

Commit

Permalink
[Cleanup] Minor cleanups
Browse files Browse the repository at this point in the history
Organized exceptions files; removed dgml file generation; remove Guid; changed Prt naming files and values to P
  • Loading branch information
Christine Zhou committed Sep 10, 2024
1 parent 39411b7 commit 637c463
Show file tree
Hide file tree
Showing 53 changed files with 1,038 additions and 1,360 deletions.
11 changes: 0 additions & 11 deletions Src/PChecker/CheckerCore/Coverage/ActivityCoverageReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ public ActivityCoverageReporter(CoverageInfo coverageInfo)
BuiltInEvents.Add(typeof(DefaultEvent).FullName);
}

/// <summary>
/// Emits the visualization graph.
/// </summary>
public void EmitVisualizationGraph(string graphFile)
{
if (CoverageInfo.CoverageGraph != null)
{
CoverageInfo.CoverageGraph.SaveDgml(graphFile, true);
}
}

/// <summary>
/// Emits the code coverage report.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ private static void MergeHashSets(Dictionary<string, HashSet<string>> ours, Dict
}
}

internal class StateMachineRuntimeLogEventCoverage : IStateMachineRuntimeLog
internal class ControlledRuntimeLogEventCoverage : IControlledRuntimeLog
{
private readonly EventCoverage InternalEventCoverage = new EventCoverage();
private Event Dequeued;

public StateMachineRuntimeLogEventCoverage()
public ControlledRuntimeLogEventCoverage()
{
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public void OnReceiveEvent(StateMachineId id, string stateName, Event e, bool wa
}

public void OnSendEvent(StateMachineId targetStateMachineId, string senderName, string senderType, string senderStateName,
Event e, Guid opGroupId, bool isTargetHalted)
Event e, bool isTargetHalted)
{
var eventName = e.GetType().FullName;
EventCoverage.AddEventSent(GetStateId(senderType, senderStateName), eventName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
namespace PChecker.Coverage
{
/// <summary>
/// Implements the <see cref="IStateMachineRuntimeLog"/> and builds a directed graph
/// Implements the <see cref="IControlledRuntimeLog"/> and builds a directed graph
/// from the recorded events and state transitions.
/// </summary>
public class StateMachineRuntimeLogGraphBuilder : IStateMachineRuntimeLog
public class ControlledRuntimeLogGraphBuilder : IControlledRuntimeLog
{
private Graph CurrentGraph;
private readonly Dictionary<StateMachineId, EventInfo> Dequeued = new Dictionary<StateMachineId, EventInfo>(); // current dequeued event.
Expand Down Expand Up @@ -50,7 +50,7 @@ private class PopStateEvent : Event
{
}

static StateMachineRuntimeLogGraphBuilder()
static ControlledRuntimeLogGraphBuilder()
{
EventAliases[typeof(GotoStateEvent).FullName] = "goto";
EventAliases[typeof(HaltEvent).FullName] = "halt";
Expand All @@ -62,9 +62,9 @@ static StateMachineRuntimeLogGraphBuilder()
}

/// <summary>
/// Initializes a new instance of the <see cref="StateMachineRuntimeLogGraphBuilder"/> class.
/// Initializes a new instance of the <see cref="ControlledRuntimeLogGraphBuilder"/> class.
/// </summary>
public StateMachineRuntimeLogGraphBuilder(bool mergeEventLinks)
public ControlledRuntimeLogGraphBuilder(bool mergeEventLinks)
{
MergeEventLinks = mergeEventLinks;
CurrentGraph = new Graph();
Expand Down Expand Up @@ -113,7 +113,7 @@ public void OnCreateStateMachine(StateMachineId id, string creatorName, string c

/// <inheritdoc/>
public void OnSendEvent(StateMachineId targetStateMachineId, string senderName, string senderType, string senderStateName,
Event e, Guid opGroupId, bool isTargetHalted)
Event e, bool isTargetHalted)
{
var eventName = e.GetType().FullName;
AddEvent(targetStateMachineId.Name, targetStateMachineId.Type, senderName, senderType, senderStateName, eventName);
Expand Down Expand Up @@ -662,11 +662,8 @@ private static string GetEventCategory(string fullyQualifiedName)
[DataContract]
public class Graph
{
internal const string DgmlNamespace = "http://schemas.microsoft.com/vs/2009/dgml";

// These [DataMember] fields are here so we can serialize the Graph across parallel or distributed
// test processes without losing any information. There is more information here than in the serialized
// DGML which is we we can't just use Save/LoadDgml to do the same.
// test processes without losing any information.

[DataMember]
private readonly Dictionary<string, GraphNode> InternalNodes = new Dictionary<string, GraphNode>();
Expand Down Expand Up @@ -797,175 +794,7 @@ internal int GetUniqueLinkIndex(GraphNode source, GraphNode target, string id)

return index;
}

/// <summary>
/// Serialize the graph to a DGML string.
/// </summary>
public override string ToString()
{
using (var writer = new StringWriter())
{
WriteDgml(writer, false);
return writer.ToString();
}
}

internal void SaveDgml(string graphFilePath, bool includeDefaultStyles)
{
using (var writer = new StreamWriter(graphFilePath, false, Encoding.UTF8))
{
WriteDgml(writer, includeDefaultStyles);
}
}

/// <summary>
/// Serialize the graph to DGML.
/// </summary>
public void WriteDgml(TextWriter writer, bool includeDefaultStyles)
{
writer.WriteLine("<DirectedGraph xmlns='{0}'>", DgmlNamespace);
writer.WriteLine(" <Nodes>");

if (InternalNodes != null)
{
var nodes = new List<string>(InternalNodes.Keys);
nodes.Sort();
foreach (var id in nodes)
{
var node = InternalNodes[id];
writer.Write(" <Node Id='{0}'", node.Id);

if (!string.IsNullOrEmpty(node.Label))
{
writer.Write(" Label='{0}'", node.Label);
}

if (!string.IsNullOrEmpty(node.Category))
{
writer.Write(" Category='{0}'", node.Category);
}

node.WriteAttributes(writer);
writer.WriteLine("/>");
}
}

writer.WriteLine(" </Nodes>");
writer.WriteLine(" <Links>");

if (InternalLinks != null)
{
var links = new List<string>(InternalLinks.Keys);
links.Sort();
foreach (var id in links)
{
var link = InternalLinks[id];
writer.Write(" <Link Source='{0}' Target='{1}'", link.Source.Id, link.Target.Id);
if (!string.IsNullOrEmpty(link.Label))
{
writer.Write(" Label='{0}'", link.Label);
}

if (!string.IsNullOrEmpty(link.Category))
{
writer.Write(" Category='{0}'", link.Category);
}

if (link.Index.HasValue)
{
writer.Write(" Index='{0}'", link.Index.Value);
}

link.WriteAttributes(writer);
writer.WriteLine("/>");
}
}

writer.WriteLine(" </Links>");
if (includeDefaultStyles)
{
writer.WriteLine(
@" <Styles>
<Style TargetType=""Node"" GroupLabel=""Error"" ValueLabel=""True"">
<Condition Expression=""HasCategory('Error')"" />
<Setter Property=""Background"" Value=""#FFC15656"" />
</Style>
<Style TargetType=""Node"" GroupLabel=""StateMachine"" ValueLabel=""True"">
<Condition Expression=""HasCategory('StateMachine')"" />
<Setter Property=""Background"" Value=""#FF57AC56"" />
</Style>
<Style TargetType=""Node"" GroupLabel=""Monitor"" ValueLabel=""True"">
<Condition Expression=""HasCategory('Monitor')"" />
<Setter Property=""Background"" Value=""#FF558FDA"" />
</Style>
<Style TargetType=""Link"" GroupLabel=""halt"" ValueLabel=""True"">
<Condition Expression=""HasCategory('halt')"" />
<Setter Property=""Stroke"" Value=""#FFFF6C6C"" />
<Setter Property=""StrokeDashArray"" Value=""4 2"" />
</Style>
<Style TargetType=""Link"" GroupLabel=""push"" ValueLabel=""True"">
<Condition Expression=""HasCategory('push')"" />
<Setter Property=""Stroke"" Value=""#FF7380F5"" />
<Setter Property=""StrokeDashArray"" Value=""4 2"" />
</Style>
<Style TargetType=""Link"" GroupLabel=""pop"" ValueLabel=""True"">
<Condition Expression=""HasCategory('pop')"" />
<Setter Property=""Stroke"" Value=""#FF7380F5"" />
<Setter Property=""StrokeDashArray"" Value=""4 2"" />
</Style>
</Styles>");
}

writer.WriteLine("</DirectedGraph>");
}

/// <summary>
/// Load a DGML file into a new Graph object.
/// </summary>
/// <param name="graphFilePath">Full path to the DGML file.</param>
/// <returns>The loaded Graph object.</returns>
public static Graph LoadDgml(string graphFilePath)
{
var doc = XDocument.Load(graphFilePath);
var result = new Graph();
var ns = doc.Root.Name.Namespace;
if (ns != DgmlNamespace)
{
throw new Exception(string.Format("File '{0}' does not contain the DGML namespace", graphFilePath));
}

foreach (var e in doc.Root.Element(ns + "Nodes").Elements(ns + "Node"))
{
var id = (string)e.Attribute("Id");
var label = (string)e.Attribute("Label");
var category = (string)e.Attribute("Category");

var node = new GraphNode(id, label, category);
node.AddDgmlProperties(e);
result.GetOrCreateNode(node);
}

foreach (var e in doc.Root.Element(ns + "Links").Elements(ns + "Link"))
{
var srcId = (string)e.Attribute("Source");
var targetId = (string)e.Attribute("Target");
var label = (string)e.Attribute("Label");
var category = (string)e.Attribute("Category");
var srcNode = result.GetOrCreateNode(srcId);
var targetNode = result.GetOrCreateNode(targetId);
var indexAttr = e.Attribute("index");
int? index = null;
if (indexAttr != null)
{
index = (int)indexAttr;
}

var link = result.GetOrCreateLink(srcNode, targetNode, index, label, category);
link.AddDgmlProperties(e);
}

return result;
}


/// <summary>
/// Merge the given graph so that this graph becomes a superset of both graphs.
Expand Down Expand Up @@ -1132,27 +961,6 @@ public GraphNode(string id, string label, string category)
Label = label;
Category = category;
}

/// <summary>
/// Add additional properties from XML element.
/// </summary>
/// <param name="e">An XML element representing the graph node in DGML format.</param>
public void AddDgmlProperties(XElement e)
{
foreach (var a in e.Attributes())
{
switch (a.Name.LocalName)
{
case "Id":
case "Label":
case "Category":
break;
default:
AddAttribute(a.Name.LocalName, a.Value);
break;
}
}
}
}

/// <summary>
Expand Down Expand Up @@ -1202,27 +1010,5 @@ public GraphLink(GraphNode source, GraphNode target, string label, string catego
Label = label;
Category = category;
}

/// <summary>
/// Add additional properties from XML element.
/// </summary>
/// <param name="e">An XML element representing the graph node in DGML format.</param>
public void AddDgmlProperties(XElement e)
{
foreach (var a in e.Attributes())
{
switch (a.Name.LocalName)
{
case "Source":
case "Target":
case "Label":
case "Category":
break;
default:
AddAttribute(a.Name.LocalName, a.Value);
break;
}
}
}
}
}

This file was deleted.

Loading

0 comments on commit 637c463

Please sign in to comment.