/// <summary> /// Method, which is called before each exploration. /// </summary> /// <param name="host"></param> /// <returns></returns> protected override object BeforeExploration(IPexExplorationComponent host) { using (var gvWriter = new StreamWriter(outFileUrl, true)) { gvWriter.WriteLine("digraph {"); gvWriter.WriteLine("node [ fontsize = \"16\" shape = \"box\" fillcolor = \"white\"];"); } using (var infoWriter = new StreamWriter(outFileUrl + ".info", true)) { infoWriter.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); infoWriter.WriteLine("<GraphInfo>"); } host.Log.ProblemHandler += (p1) => { try { var nodeStorage = host.GetService <PexExecutionNodeStorageComponent>(); nodeStorage.Z3Locations.Add((p1.FlippedLocation.Method == null ? "" : (p1.FlippedLocation.Method.FullName + ":" + p1.FlippedLocation.Offset))); } catch (Exception ex) { // TODO : Exception handling? } }; using (var testWriter = new StreamWriter(outFileUrl + ".tests", true)) { testWriter.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); testWriter.WriteLine("<Methods>"); } host.Log.GeneratedTestHandler += (p1) => { try { var currentRun = p1.GeneratedTest.Run; var runStorage = host.GetService <PexRunAndTestStorageComponent>(); using (var testWriter = new StreamWriter(outFileUrl + ".tests", true)) { testWriter.WriteLine("<MethodCode Run=\"" + currentRun + "\" Exception=\"" + p1.GeneratedTest.ExceptionState + "\" Failed=\"" + p1.GeneratedTest.IsFailure + "\"><![CDATA["); testWriter.WriteLine(p1.GeneratedTest.MethodCode); testWriter.WriteLine("]]></MethodCode>"); } runStorage.Runs.Add(new Tuple <int, int>(currentRun, p1.GeneratedTest.IsFailure ? 2 : 1)); } catch (Exception ex) { // TODO : Exception handling? } }; return(null); }
public void AfterExploration(IPexExplorationComponent host, object data) { var graph = host.ExplorationServices.Searcher.ExecutionGraphBuilder as IVisualExecutionGraph; log = host.GetService<ProblemTrackDatabase>().SimpleLog; AppendLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); foreach (var rootNode in graph.ExecutionRootNodes) { LogRootNode(host, log, rootNode); } AppendLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); AppendLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); IFiniteMap<TypeName, StackFrameTree<PexStackFrameTag>.ExceptionNode> exceptions = host.Log.ExceptionFrameTree.GetExceptions(); foreach (var exception in exceptions) { AppendLine("TypeName: " + exception.Key); IIndexable<PexGeneratedTestName> indexable = exception.Value.Tag.Tests; foreach (var name in indexable) { AppendLine("ExceptionNode.Tag.Test: id: " + name.ID + " method: "+name.TestMethodName); } AppendLine("ExceptionNode.Tag.ExceptionState: " + exception.Value.Tag.ExceptionState); } AppendLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); return; }
public void AfterExploration(IPexExplorationComponent host, object data) { var graph = host.ExplorationServices.Searcher.ExecutionGraphBuilder as IVisualExecutionGraph; log = host.GetService <ProblemTrackDatabase>().SimpleLog; AppendLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); foreach (var rootNode in graph.ExecutionRootNodes) { LogRootNode(host, log, rootNode); } AppendLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); AppendLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); IFiniteMap <TypeName, StackFrameTree <PexStackFrameTag> .ExceptionNode> exceptions = host.Log.ExceptionFrameTree.GetExceptions(); foreach (var exception in exceptions) { AppendLine("TypeName: " + exception.Key); IIndexable <PexGeneratedTestName> indexable = exception.Value.Tag.Tests; foreach (var name in indexable) { AppendLine("ExceptionNode.Tag.Test: id: " + name.ID + " method: " + name.TestMethodName); } AppendLine("ExceptionNode.Tag.ExceptionState: " + exception.Value.Tag.ExceptionState); } AppendLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); return; }
/// <summary> /// Gets invoked after the exploration /// </summary> /// <param name="host"></param> /// <param name="data"></param> void IPexExplorationPackage.AfterExploration(IPexExplorationComponent host, object data) { if (this.explorationObserver == null) { this.explorationObserver = host.GetService <IFieldAccessExplorationObserver>(); } this.explorationObserver.Dump(); }
/// <summary> /// Method, which is called after each exploration. /// </summary> /// <param name="host"></param> /// <param name="data"></param> protected override void AfterExploration(IPexExplorationComponent host, object data) { base.AfterExploration(host, data); var runStorage = host.GetService <PexRunAndTestStorageComponent>(); var nodeStorage = host.GetService <PexExecutionNodeStorageComponent>(); using (var testWriter = new StreamWriter(outFileUrl + ".tests", true)) { testWriter.WriteLine("</Methods>"); } using (StreamWriter runWriter = new StreamWriter(outFileUrl + ".runs", true)) { foreach (var run in runStorage.Runs.OrderBy(t => t.Item1)) { StringBuilder indexes = new StringBuilder(); foreach (var node in runStorage.NodesInPath[run.Item1]) { indexes.Append(node); indexes.Append(","); } indexes.Remove(indexes.Length - 1, 1); runWriter.WriteLine(run.Item1 + "|" + run.Item2 + "|" + indexes.ToString()); } } var gvStringBuilder = new StringBuilder(); foreach (var node in nodeStorage.NodeLocations) { if (nodeStorage.Z3Locations.Contains(node.Value)) { gvStringBuilder.AppendLine(node.Key + " [shape=ellipse]"); } } foreach (var run in runStorage.Runs.OrderBy(t => t.Item1)) { int last = -1; if (runStorage.NodesInPath.ContainsKey(run.Item1)) { last = runStorage.NodesInPath[run.Item1].Last(); } if (last != -1) { gvStringBuilder.AppendLine(last + " [fillcolor=" + ((run.Item2 == 0) ? "orange" : (run.Item2 == 1 ? "limegreen" : "firebrick")) + "]"); } } gvStringBuilder.AppendLine("}"); using (var gvWriter = new StreamWriter(outFileUrl, true)) { gvWriter.WriteLine(gvStringBuilder.ToString()); } using (var exhWriter = new StreamWriter(outFileUrl + ".exh", true)) { foreach (var node in nodeStorage.NodeInstances) { exhWriter.WriteLine(node.Key + "|" + node.Value.ExhaustedReason); } } using (var infoWriter = new StreamWriter(outFileUrl + ".info", true)) { infoWriter.WriteLine("</GraphInfo>"); } /* * using (var metaWriter = new StreamWriter(outFileUrl + ".metainfo")) * { * metaWriter.WriteLine("maxdepth:"+nodeStorage.NodeInstances.Max(n => n.Value.Depth)); * metaWriter.WriteLine("nodecount:"+nodeStorage.NodeInstances.Count); * }*/ // Invoking GraphViz string strCmdText = "/C dot -Tplain-ext -o " + outFileUrl + ".plain " + outFileUrl; System.Diagnostics.Process.Start("CMD.exe", strCmdText); var dir = outFileUrl.TrimEnd(outFileUrl.Split('\\').Last().ToCharArray()); string fileName = outFileUrl.Split('\\').Last(); // Waiting GraphViz to complete... TODO Thread.Sleep(5000); using (ZipFile zip = new ZipFile()) { zip.AddFile(dir + fileName, "files"); zip.AddFile(dir + fileName + ".plain", "files"); zip.AddFile(dir + fileName + ".info", "files"); zip.AddFile(dir + fileName + ".runs", "files"); zip.AddFile(dir + fileName + ".tests", "files"); zip.AddFile(dir + fileName + ".exh", "files"); zip.Save(dir + fileName + ".sviz"); } // Deleting temporary files File.Delete(dir + fileName); File.Delete(dir + fileName + ".plain"); File.Delete(dir + fileName + ".info"); File.Delete(dir + fileName + ".runs"); File.Delete(dir + fileName + ".tests"); File.Delete(dir + fileName + ".exh"); }