private bool Check(Options opts) { bool result = true; bool isAdd = this.reset; bool isDel; Tuple <OptValueKind, object>[] delFiles; result = ValidateOption(opts, DelOption, true, 1, int.MaxValue, out isDel, out delFiles) && result; bool isDescr; Tuple <OptValueKind, object>[] descrs; result = ValidateOption(opts, DescrOption, true, 1, int.MaxValue, out isDescr, out descrs) && result; string[] unknownOpts; if (opts.TryGetOptionsBesides(AllOptions, out unknownOpts)) { foreach (var uo in unknownOpts) { WriteError("ERROR: -{0} is not a legal option", uo); } result = false; } if (!result) { Console.WriteLine(); PrintUsage(); return(false); } if (isDescr) { var fullDescr = ""; foreach (var v in descrs) { fullDescr += v.Item2.ToString() + " "; } Description = fullDescr; Console.WriteLine("*********** Checking {0}***********", fullDescr); } if (isDel) { foreach (var df in delFiles) { try { var dfi = new FileInfo(Path.Combine(activeDirectory, df.Item2.ToString())); if (dfi.Exists) { Console.WriteLine("DEL: Deleted file {0}", dfi.FullName); dfi.Attributes = FileAttributes.Normal; dfi.Delete(); } } catch (Exception e) { WriteError( "Error deleting file {0} - {1}", df.Item2, e.Message); } } } StreamWriter tmpWriter; if (!OpenTmpStream(out tmpWriter)) { return(false); } Console.WriteLine("Running test under {0} ...", activeDirectory); const string acceptorFilePattern = "acc_0.txt"; DirectoryInfo di = new DirectoryInfo(activeDirectory); if (isAdd) { foreach (var acci in di.EnumerateFiles(acceptorFilePattern)) { File.Delete(Path.Combine(activeDirectory, acci.FullName)); } } string workDirectory = new DirectoryInfo(activeDirectory).Parent.FullName; bool isInclPc; Tuple <OptValueKind, object>[] includesPc; bool isArgsPc; Tuple <OptValueKind, object>[] pcArgs; bool isInclZinger; Tuple <OptValueKind, object>[] includesZinger; bool isArgsZinger; Tuple <OptValueKind, object>[] zingerArgs; bool isInclPrt; Tuple <OptValueKind, object>[] includesPrt; bool isArgsPrt; Tuple <OptValueKind, object>[] prtArgs; try { //Run the component of the P tool chain specified by the "activeDirectory": if (parentDir == "Pc") { foreach (string fileName in Directory.EnumerateFiles(workDirectory)) { if (Path.GetExtension(fileName) == ".c" || Path.GetExtension(fileName) == ".h" || Path.GetExtension(fileName) == ".4ml" || Path.GetExtension(fileName) == ".zing" || Path.GetExtension(fileName) == ".dll") { File.Delete(fileName); } } result = ValidateOption(opts, IncludePcOption, true, 1, int.MaxValue, out isInclPc, out includesPc) && result; result = ValidateOption(opts, ArgsPcOption, true, 1, int.MaxValue, out isArgsPc, out pcArgs) && result; tmpWriter.WriteLine("================================="); tmpWriter.WriteLine(" Console output "); tmpWriter.WriteLine("================================="); string inputFileName; bool liveness; ParsePcArgs(pcArgs.Select(x => x.Item2), out inputFileName, out liveness); var compileArgs = new CommandLineOptions(); compileArgs.inputFileNames = new List <string>(); compileArgs.inputFileNames.Add(inputFileName); compileArgs.compilerOutput = CompilerOutput.C; compileArgs.shortFileNames = true; compileArgs.outputDir = workDirectory; compileArgs.shortFileNames = true; compileArgs.profile = true; var compilerOutput = new CompilerTestOutputStream(tmpWriter); bool compileResult = false; using (compiler.Profiler.Start("compile", inputFileName)) { compileResult = compiler.Compile(compilerOutput, compileArgs); } if (compileResult) { // link the *.4ml compileArgs.inputFileNames.Clear(); string linkFileName = Path.ChangeExtension(inputFileName, ".4ml"); compileArgs.inputFileNames.Add(linkFileName); using (compiler.Profiler.Start("link", linkFileName)) { compileResult = compiler.Link(compilerOutput, compileArgs); } if (compileResult) { // compile *.p again, this time with Zing option. compileArgs.inputFileNames.Clear(); compileArgs.inputFileNames.Add(inputFileName); compileArgs.compilerOutput = CompilerOutput.Zing; if (liveness) { compileArgs.liveness = LivenessOption.Standard; } using (compiler.Profiler.Start("compile zing", linkFileName)) { compileResult = compiler.Compile(compilerOutput, compileArgs); } } } if (compileResult) { tmpWriter.WriteLine("EXIT: 0"); } else { tmpWriter.WriteLine("EXIT: -1"); } } else if (parentDir == "Zing") { result = ValidateOption(opts, IncludeZingerOption, true, 1, int.MaxValue, out isInclZinger, out includesZinger) && result; result = ValidateOption(opts, ArgsZingerOption, true, 1, int.MaxValue, out isArgsZinger, out zingerArgs) && result; //TODO: since Zinger returns "true" when *.dll file is missing, catch this case by explicitly //checking if files specified as zinger arguments are present (unless Zinger is fixed //and returns "false" for such errors). //The error message should give a tip: "Make sure pc.exe was called and run successfully" // zingerResult will be false only if zinger command line call didn't work; // otherwise, it will be "true", even if Zinger's exit value is non-zero // TODO: catch Zinger's exit code 7 (wrong parameters) and report it to cmd window string zingDllName = null; foreach (var fileName in Directory.EnumerateFiles(workDirectory)) { if (Path.GetExtension(fileName) == ".dll") { zingDllName = Path.GetFullPath(fileName); break; } } if (zingDllName == null) { WriteError("Zinger input not found."); return(false); } Tuple <OptValueKind, object> zingerDefaultArg = new Tuple <OptValueKind, object>(OptValueKind.String, zingDllName); var lst = new List <Tuple <OptValueKind, object> >(); if (zingerArgs != null) { lst = zingerArgs.ToList(); lst.Add(zingerDefaultArg); zingerArgs = lst.ToArray(); } else { zingerArgs = new Tuple <OptValueKind, object> [1]; zingerArgs[0] = zingerDefaultArg; } bool zingerResult = false; using (compiler.Profiler.Start("run zing", zingDllName)) { zingerResult = Run(tmpWriter, zingFilePath, zingerArgs); } //debug: if (!zingerResult) { result = false; } else if (isInclZinger && !AppendIncludes(tmpWriter, includesZinger)) { result = false; } } else if (parentDir == "Prt") { result = ValidateOption(opts, IncludePrtOption, true, 1, int.MaxValue, out isInclPrt, out includesPrt) && result; result = ValidateOption(opts, ArgsPrtOption, true, 1, int.MaxValue, out isArgsPrt, out prtArgs) && result; // copy Tester.vcxproj and tester.c into this test directory (so we can run multiple tests in parallel). CopyFiles(Path.Combine(this.testRoot, "PrtTester"), workDirectory); string exePath = configuration + Path.DirectorySeparatorChar + platform; string testerExeDir = Path.Combine(workDirectory, exePath); this.testerExePath = Path.Combine(testerExeDir, "tester.exe"); //Build tester.exe for the updated runtime files. var prtTesterProj = Path.Combine(workDirectory, "Tester.vcxproj"); using (compiler.Profiler.Start("build prttester", workDirectory)) { //1. Define msbuildPath for msbuild.exe: var msbuildPath = FindTool("MSBuild.exe"); if (msbuildPath == null) { string programFiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)"); if (string.IsNullOrEmpty(programFiles)) { programFiles = Environment.GetEnvironmentVariable("ProgramFiles"); } msbuildPath = Path.Combine(programFiles, @"MSBuild\14.0\Bin\MSBuild.exe"); if (!File.Exists(msbuildPath)) { WriteError("Error: msbuild.exe is not in your PATH."); return(false); } } //2. Build Tester: "msbuildDir .\PrtTester\Tester.vcxproj /p:Configuration=Debug /verbosity:quiet /nologo" //Check that Tester.vcxproj exists under PrtTester: if (!File.Exists(prtTesterProj)) { WriteError("Error: Tester.vcxproj is not found"); return(false); } //Checking that linker.c and linker.h have been copied into testerDirectory: if (!File.Exists(Path.Combine(workDirectory, "linker.c")) || !File.Exists(Path.Combine(workDirectory, "linker.h"))) { WriteError("Error: linker.c and linker.h are not found, did you run pc.exe ?"); return(false); } //Cleaning tester.exe: bool buildRes = RunBuildTester(msbuildPath, prtTesterProj, true); if (!buildRes) { WriteError("Error cleaning Tester project"); return(false); } //Building tester.exe: buildRes = RunBuildTester(msbuildPath, prtTesterProj, false); if (!buildRes) { WriteError("Error building Tester project"); return(false); } } bool prtResult = false; using (compiler.Profiler.Start("run prttester", workDirectory)) { //Run tester.exe: prtResult = Run(tmpWriter, testerExePath, prtArgs); } if (!prtResult) { result = false; } else if (isInclPrt && !AppendIncludes(tmpWriter, includesPrt)) { result = false; } } else { WriteError("Invalid test directory {0}, expecting 'pc','prt' or 'zing'.", parentDir); return(false); } } catch (Exception e) { WriteError("ERROR running P tool: {0}", e.Message); return(false); } if (!CloseTmpStream(tmpWriter)) { result = false; } if (result && !CompareAcceptors(activeDirectory, isAdd)) { File.Delete(Path.Combine(activeDirectory, LogFile)); File.Copy( Path.Combine(activeDirectory, TmpStreamFile), Path.Combine(activeDirectory, LogFile)); Console.WriteLine("LOGGED: Saved bad output to {0}", Path.Combine(activeDirectory, LogFile)); result = false; } if (!DeleteTmpFile()) { result = false; } if (result) { Console.WriteLine("SUCCESS: Output matched"); } return(result); }
private int TestPc( TestConfig config, TextWriter tmpWriter, DirectoryInfo workDirectory, string activeDirectory, CompilerOutput outputLanguage) { List <string> pFiles = workDirectory.EnumerateFiles("*.p").Select(pFile => pFile.FullName).ToList(); if (!pFiles.Any()) { throw new Exception("no .p file found in test directory"); } string inputFileName = pFiles.First(); string linkFileName = Path.ChangeExtension(inputFileName, ".4ml"); var compilerOutput = new CompilerTestOutputStream(tmpWriter); var compileArgs = new CommandLineOptions { inputFileNames = new List <string>(pFiles), shortFileNames = true, outputDir = workDirectory.FullName, unitName = linkFileName, //liveness = LivenessOption.None, liveness = outputLanguage == CompilerOutput.Zing && config.Arguments.Contains("/liveness") ? LivenessOption.Standard : LivenessOption.None, compilerOutput = outputLanguage }; // Compile if (!PCompiler.Value.Compile(compilerOutput, compileArgs)) //if (!PCompilerService.Value.Compile(compilerOutput, compileArgs)) { tmpWriter.WriteLine("EXIT: -1"); return(-1); } //(TODO)Skip the link step if outputLanguage == CompilerOutput.CSharp? // Link compileArgs.dependencies.Add(linkFileName); compileArgs.inputFileNames.Clear(); if (config.Link != null) { compileArgs.inputFileNames.Add(Path.Combine(activeDirectory, config.Link)); } if (!PCompiler.Value.Link(compilerOutput, compileArgs)) //if(!PCompilerService.Value.Link(compilerOutput, compileArgs)) { tmpWriter.WriteLine("EXIT: -1"); return(-1); } else { tmpWriter.WriteLine("EXIT: 0"); } return(0); }
private int TestPc( TestConfig config, TextWriter tmpWriter, DirectoryInfo workDirectory, string activeDirectory, CompilerOutput outputLanguage) { List <string> pFiles = workDirectory.EnumerateFiles("*.p").Select(pFile => pFile.FullName).ToList(); if (!pFiles.Any()) { throw new Exception("no .p file found in test directory"); } string inputFileName = pFiles.First(); string linkFileName = Path.ChangeExtension(inputFileName, ".4ml"); var compilerOutput = new CompilerTestOutputStream(tmpWriter); var compileArgs = new CommandLineOptions { inputFileNames = new List <string>(pFiles), shortFileNames = true, outputDir = workDirectory.FullName, unitName = linkFileName, //liveness = LivenessOption.None, liveness = outputLanguage == CompilerOutput.Zing && config.Arguments.Contains("/liveness") ? LivenessOption.Standard : LivenessOption.None, compilerOutput = outputLanguage }; // Compile if (!PCompiler.Value.Compile(compilerOutput, compileArgs)) { tmpWriter.WriteLine("EXIT: -1"); return(-1); } //Skip the link step if outputLanguage == CompilerOutput.CSharp? // Link //if (!(outputLanguage == CompilerOutput.CSharp)) //{ compileArgs.dependencies.Add(linkFileName); compileArgs.inputFileNames.Clear(); if (config.Link != null) { compileArgs.inputFileNames.Add(Path.Combine(activeDirectory, config.Link)); } if (!PCompiler.Value.Link(compilerOutput, compileArgs)) { tmpWriter.WriteLine("EXIT: -1"); return(-1); } //} //pc.exe with Zing option is called when outputLanguage is C; //pc.exe with CSharp option is called when outputLanguage is CSharp; //if (outputLanguage == CompilerOutput.C) //{ // // compile *.p again, this time with Zing option: // compileArgs.compilerOutput = CompilerOutput.Zing; // compileArgs.inputFileNames = new List<string>(pFiles); // compileArgs.dependencies.Clear(); // int zingResult = PCompiler.Compile(compilerOutput, compileArgs) ? 0 : -1; // tmpWriter.WriteLine($"EXIT: {zingResult}"); // if (!(zingResult == 0)) // { // return -1; // } //} //if (outputLanguage == CompilerOutput.CSharp) //{ // // compile *.p again, this time with CSharp option: // compileArgs.compilerOutput = CompilerOutput.CSharp; // compileArgs.inputFileNames = new List<string>(pFiles); // compileArgs.dependencies.Clear(); // if (!PCompiler.Compile(compilerOutput, compileArgs)) // { // tmpWriter.WriteLine("EXIT: -1"); // return -1; // } // else // { // tmpWriter.WriteLine("EXIT: 0"); // } // // Link // compileArgs.dependencies.Add(linkFileName); // compileArgs.inputFileNames.Clear(); // if (config.Link != null) // { // compileArgs.inputFileNames.Add(Path.Combine(activeDirectory, config.Link)); // } // if (!PCompiler.Link(compilerOutput, compileArgs)) // { // tmpWriter.WriteLine("EXIT: -1"); // return -1; // } //} return(0); }