internal void TestRunnerRunOnly(string includePath, string code, Dictionary <int, List <string> > map /*, string executionLogFilePath*/) { ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner(); ProtoScript.Config.RunConfiguration runnerConfig; // Specify some of the requirements of IDE. core.Options.ExecutionMode = ProtoCore.ExecutionMode.Serial; core.Options.SuppressBuildOutput = false; core.Options.WatchTestMode = true; core.Options.GCTempVarsOnDebug = false; // Cyclic dependency threshold is lowered from the default (2000) // as this causes the test framework to be painfully slow core.Options.kDynamicCycleThreshold = 5; // Pass the absolute path so that imported filepaths can be resolved // in "FileUtils.GetDSFullPathName()" if (!String.IsNullOrEmpty(includePath)) { includePath = Path.GetDirectoryName(includePath); core.Options.IncludeDirectories.Add(includePath); } //StreamWriter sw = File.CreateText(executionLogFilePath); TextOutputStream fs = new TextOutputStream(map); // By specifying this option we inject a mock Executive ('InjectionExecutive') // that prints stackvalues at every assignment statement // by overriding the POP_handler instruction - pratapa // core.ExecutiveProvider = new InjectionExecutiveProvider(); core.BuildStatus.MessageHandler = fs; core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core)); core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core)); runnerConfig = new ProtoScript.Config.RunConfiguration(); runnerConfig.IsParrallel = false; DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper()); //Run RuntimeCore runtimeCore = null; Mirror = fsr.Execute(code, core, out runtimeCore); //sw.Close(); runtimeCore.Cleanup(); }
public static void CompareDebugAndRunResults(string code, string defectID = "") { Core runCore = null; RuntimeCore runtimeCore = null; try { runCore = TestRunnerRunOnly(code, out runtimeCore); } catch (Exception e) { Assert.Ignore("Ignored due to Exception from run: " + e.ToString()); } { RuntimeCore debugRuntimeCore = null; Core debugRunCore = DebugRunnerRunOnly(code, out debugRuntimeCore); CompareCores(runtimeCore, debugRuntimeCore, defectID); debugRuntimeCore.Cleanup(); } { RuntimeCore stepOverRuntimeCore = null; Core stepOverCore = DebugRunnerStepOver(code, out stepOverRuntimeCore); CompareCores(runtimeCore, stepOverRuntimeCore, defectID); stepOverRuntimeCore.Cleanup(); } { RuntimeCore stepInRuntimeCore = null; Core stepInCore = DebugRunerStepIn(code, out stepInRuntimeCore); CompareCores(runtimeCore, stepInRuntimeCore, defectID); stepInRuntimeCore.Cleanup(); } runtimeCore.Cleanup(); }
public void CleanUp() { testRuntimeCore.Cleanup(); }
public static void RunAndCompare(string scriptFile) { Dictionary <int, List <string> > map = new Dictionary <int, List <string> >(); String includePath = Path.GetFullPath(scriptFile); StreamReader file = new StreamReader(scriptFile); WatchTestFx.GeneratePrintStatements(file, ref map); file = new StreamReader(scriptFile); String code = file.ReadToEnd(); file.Close(); InjectionExecutive.ExpressionMap.Clear(); ExecutionMirror mirror; Core core = TestRunnerRunOnly(includePath, code, map, "ManagedAsmGeometry.dll", "ManagedAsmPersistentManager.dll", out mirror); RuntimeCore runtimeCore = core.__TempCoreHostForRefactoring; try { //XML Result Dictionary <Expression, List <string> > expressionValues = InjectionExecutive.ExpressionMap; string xmlFile = Path.GetFileName(Path.ChangeExtension(scriptFile, ".xml")); string baseXmlFile = Path.Combine(BaseDir, xmlFile); string outputXmlFile = Path.Combine(ScriptDir, xmlFile); DumpDictionaryAsXml(expressionValues, outputXmlFile); //Log string logFile = Path.GetFileName(Path.ChangeExtension(scriptFile, ".log")); string baseLogFile = Path.Combine(BaseDir, logFile); string outputLogFile = Path.Combine(ScriptDir, logFile); TextOutputStream tStream = core.BuildStatus.MessageHandler as TextOutputStream; StreamWriter osw = new StreamWriter(outputLogFile); osw.Write(tStream.ToString()); if (null != mirror) { osw.Write(mirror.GetCoreDump()); } osw.Close(); //Compare XML StringBuilder msg = new StringBuilder(); bool xmlFilesAreSame = CompareXml(outputXmlFile, baseXmlFile, msg); if (!xmlFilesAreSame) { bool logFilesAreSame = CompareLog(outputLogFile, baseLogFile); //There may be some errors when comparing .xml files if (logFilesAreSame) { Assert.Ignore("Ignored: .xml files are the same while .log files are not the same!"); } else { Assert.Fail(msg.ToString()); } } } catch (NUnit.Framework.AssertionException e) { runtimeCore.Cleanup(); Assert.Fail(e.Message); return; } catch (Exception e) { runtimeCore.Cleanup(); Assert.Fail("Error: an exception is thrown!\n\n\t" + e.Message); return; } //Ensure no memory leak //sw.Close(); runtimeCore.Cleanup(); }
internal static void DebugRunnerStepIn(string includePath, string code, /*string logFile*/ Dictionary <int, List <string> > map, bool watchNestedMode = false, string defectID = "") { //Internal setup ProtoCore.Core core; DebugRunner fsr; // Specify some of the requirements of IDE. var options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; options.GCTempVarsOnDebug = false; // Cyclic dependency threshold is lowered from the default (2000) // as this causes the test framework to be painfully slow options.kDynamicCycleThreshold = 5; // Pass the absolute path so that imported filepaths can be resolved // in "FileUtils.GetDSFullPathName()" if (!String.IsNullOrEmpty(includePath)) { includePath = Path.GetDirectoryName(includePath); options.IncludeDirectories.Add(includePath); } core = new ProtoCore.Core(options); core.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(core)); core.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(core)); fsr = new DebugRunner(core); DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper()); //Run fsr.PreStart(code); RuntimeCore runtimeCore = fsr.runtimeCore; //StreamReader log = new StreamReader(logFile); //bool isPrevBreakAtPop = false; int lineAtPrevBreak = -1; string symbolName = null; DebugRunner.VMState vms = null; while (!fsr.isEnded) { vms = fsr.LastState; OpCode opCode = OpCode.NONE; DebugInfo debug = null; if (vms != null) { // check if previous break is a POP // if so, get the line no. and LHS opCode = fsr.CurrentInstruction.opCode; debug = fsr.CurrentInstruction.debug; if (opCode == ProtoCore.DSASM.OpCode.POP) { //isPrevBreakAtPop = true; lineAtPrevBreak = vms.ExecutionCursor.StartInclusive.LineNo; } } DebugRunner.VMState currentVms = fsr.Step(); //if (isPrevBreakAtPop) if (debug != null) { // Do not do the verification for imported DS files, for which the FilePath is non null if (debug.Location.StartInclusive.SourceLocation.FilePath == null) { if (opCode == ProtoCore.DSASM.OpCode.POP) { VerifyWatch_Run(lineAtPrevBreak, runtimeCore.DebugProps.CurrentSymbolName, core, runtimeCore, map, watchNestedMode, defectID: defectID); } // if previous breakpoint was at a CALLR else if (opCode == ProtoCore.DSASM.OpCode.CALLR) { if (runtimeCore.DebugProps.IsPopmCall) { int ci = (int)currentVms.mirror.MirrorTarget.rmem.GetAtRelative(ProtoCore.DSASM.StackFrame.kFrameIndexClass).opdata; VerifyWatch_Run(InjectionExecutive.callrLineNo, runtimeCore.DebugProps.CurrentSymbolName, core, runtimeCore, map, watchNestedMode, ci, defectID); } } } } //isPrevBreakAtPop = false; } runtimeCore.Cleanup(); }