internal static ProtoCore.Core TestRunnerRunOnly(string includePath, string code, Dictionary <int, List <string> > map, string geometryFactory, string persistentManager, out ExecutionMirror mirror) { ProtoCore.Core core; ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner(); ProtoScript.Config.RunConfiguration runnerConfig; // Specify some of the requirements of IDE. var options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; options.SuppressBuildOutput = false; options.WatchTestMode = true; // 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()" includePath = Path.GetDirectoryName(includePath); options.IncludeDirectories.Add(includePath); //StreamWriter sw = File.CreateText(executionLogFilePath); TextOutputStream fs = new TextOutputStream(map); core = new ProtoCore.Core(options); core.Configurations.Add(ConfigurationKeys.GeometryXmlProperties, true); //core.Configurations.Add(ConfigurationKeys.GeometryFactory, geometryFactory); //core.Configurations.Add(ConfigurationKeys.PersistentManager, persistentManager); // 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 mirror = fsr.Execute(code, core); //sw.Close(); return(core); }
public static bool RunAndCompareNoAssert(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; ProtoLanguage.CompileStateTracker compileState = null; Core core = TestRunnerRunOnly(includePath, code, map, "ManagedAsmGeometry.dll", "ManagedAsmPersistentManager.dll", out mirror, out compileState); //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 = compileState.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(); if (!CompareXml(outputXmlFile, baseXmlFile, msg)) { return(false); } //Compare Log if (!CompareLog(outputLogFile, baseLogFile)) { return(false); } //sw.Close(); return(true); }
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.RuntimeStatus.MessageHandler = fs; core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core)); core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core)); runnerConfig = new ProtoScript.Config.RunConfiguration(); runnerConfig.IsParrallel = false; DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper()); //Run Mirror = fsr.Execute(code, core); //sw.Close(); core.Cleanup(); }
public static ProtoCore.Core RunAndGenerateBase(string scriptFile, string outputDir, string geometryFactory, string persistentManager) { 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; ProtoLanguage.CompileStateTracker compileState = null; Core core = TestRunnerRunOnly(includePath, code, map, geometryFactory, persistentManager, out mirror, out compileState); //XML Result Dictionary <Expression, List <string> > expressionValues = InjectionExecutive.ExpressionMap; string xmlFile = Path.GetFileName(Path.ChangeExtension(scriptFile, ".xml")); string outputXmlFile = Path.Combine(outputDir, xmlFile); DumpDictionaryAsXml(expressionValues, outputXmlFile); //Log string logFile = Path.GetFileName(Path.ChangeExtension(scriptFile, ".log")); string outputLogFile = Path.Combine(outputDir, logFile); TextOutputStream tStream = compileState.BuildStatus.MessageHandler as TextOutputStream; StreamWriter osw = new StreamWriter(outputLogFile); osw.Write(tStream.ToString()); if (null != mirror) { osw.Write(mirror.GetCoreDump()); } osw.Close(); return(core); }
internal void Print(StackValue sv, int lineNo, string symbolName, int ci = Constants.kInvalidIndex) { //TODO: Change Execution mirror class to have static methods, so that an instance does not have to be created ProtoCore.DSASM.Mirror.ExecutionMirror mirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(this, Core); string result = mirror.GetStringValue(sv, Core.Heap, 0, true); TextOutputStream tStream = Core.BuildStatus.MessageHandler as TextOutputStream; if (tStream != null) { Dictionary <int, List <string> > map = tStream.Map; //foreach(var kv in tStream.Map) if (!map.ContainsKey(lineNo)) { return; } List <string> expressions = map[lineNo]; foreach (var exp in expressions) { // Get lhs symbol name string lhsName = null; int index = exp.IndexOf('.'); if (index != -1) { string[] parts = exp.Split('.'); lhsName = parts[parts.Length - 1]; } else { Match m = Regex.Match(exp, @"(\w+)"); if (m.Success) { lhsName = m.Groups[1].Value; } } if (lhsName.Equals(symbolName)) { // Add to map Expression expStruct = new Expression(lineNo, exp, ci); if (ExpressionMap.ContainsKey(expStruct)) { List <string> values = ExpressionMap[expStruct]; values.Add(result); } else { List <string> values = new List <string>(); values.Add(result); ExpressionMap.Add(expStruct, values); } } } } }
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(); }