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); }
private static void TestZing(TestConfig config, TextWriter tmpWriter, DirectoryInfo workDirectory, string activeDirectory) { // Find Zing tool string zingFilePath = Path.Combine( Constants.SolutionDirectory, "Bld", "Drops", Constants.Configuration, Constants.Platform, "Binaries", "zinger.exe"); if (!File.Exists(zingFilePath)) { throw new Exception("Could not find zinger.exe"); } // Find DLL input to Zing string zingDllName = (from fileName in workDirectory.EnumerateFiles() where fileName.Extension == ".dll" && !fileName.Name.Contains("linker") select fileName.FullName).FirstOrDefault(); if (zingDllName == null) { throw new Exception("Could not find Zinger input."); } // Run Zing tool var arguments = new List <string>(config.Arguments) { zingDllName }; string stdout, stderr; int exitCode = ProcessHelper.RunWithOutput(zingFilePath, activeDirectory, arguments, out stdout, out stderr); tmpWriter.Write(stdout); tmpWriter.Write(stderr); tmpWriter.WriteLine($"EXIT: {exitCode}"); // Append includes foreach (string include in config.Includes) { tmpWriter.WriteLine(); tmpWriter.WriteLine("================================="); tmpWriter.WriteLine(include); tmpWriter.WriteLine("================================="); try { using (var sr = new StreamReader(Path.Combine(activeDirectory, include))) { while (!sr.EndOfStream) { tmpWriter.WriteLine(sr.ReadLine()); } } } catch (FileNotFoundException) { if (!include.EndsWith("trace")) { throw; } } } }
public void TestProgramAndBackends(DirectoryInfo origTestDir, Dictionary <TestType, TestConfig> testConfigs) { // First step: clone test folder to new spot DirectoryInfo workDirectory = PrepareTestDir(origTestDir); File.Delete(Path.Combine(Constants.TestDirectory, Constants.DisplayDiffsFile)); foreach (KeyValuePair <TestType, TestConfig> kv in testConfigs.OrderBy(kv => kv.Key)) { TestType testType = kv.Key; TestConfig config = kv.Value; Console.WriteLine($"*** {config.Description}"); string activeDirectory = Path.Combine(workDirectory.FullName, testType.ToString()); // Delete temp files as specified by test configuration. IEnumerable <FileInfo> toDelete = config .Deletes.Select(file => new FileInfo(Path.Combine(activeDirectory, file))).Where(file => file.Exists); foreach (FileInfo fileInfo in toDelete) { fileInfo.Delete(); } var sb = new StringBuilder(); using (var tmpWriter = new StringWriter(sb)) { //WriteHeader(tmpWriter); int pcResult; switch (testType) { case TestType.Pc: //Console.WriteLine("RunPc option; Running TestPc"); WriteHeader(tmpWriter); TestPc(config, tmpWriter, workDirectory, activeDirectory, CompilerOutput.C); if (Constants.RunPc || Constants.RunAll) { CheckResult(activeDirectory, origTestDir, testType, sb, true); } else { CheckResult(activeDirectory, origTestDir, testType, sb, false); } break; case TestType.Prt: if (Constants.RunPrt || Constants.RunAll) { //Console.WriteLine("RunPrt option; Running TestPrt"); WriteHeader(tmpWriter); TestPrt(config, tmpWriter, workDirectory, activeDirectory); CheckResult(activeDirectory, origTestDir, testType, sb, true); } break; case TestType.Pt: if (Constants.RunPt || Constants.RunAll) { //Console.WriteLine("RunPt option; Running TestPc and TestPt"); WriteHeader(tmpWriter); pcResult = TestPc(config, tmpWriter, workDirectory, activeDirectory, CompilerOutput.CSharp); //CheckResult(activeDirectory, origTestDir, testType, sb); if (pcResult == 0) { WriteHeader(tmpWriter); TestPt(config, tmpWriter, workDirectory, activeDirectory, origTestDir); CheckResult(activeDirectory, origTestDir, testType, sb, true); } } break; case TestType.Zing: if (Constants.RunZing || Constants.RunAll) { //Console.WriteLine("RunZing option; Running TestPc andTestZing"); WriteHeader(tmpWriter); pcResult = TestPc(config, tmpWriter, workDirectory, activeDirectory, CompilerOutput.Zing); //CheckResult(activeDirectory, origTestDir, testType, sb); if (pcResult == 0) { WriteHeader(tmpWriter); TestZing(config, tmpWriter, workDirectory, activeDirectory); CheckResult(activeDirectory, origTestDir, testType, sb, true); } } break; default: throw new ArgumentOutOfRangeException(); } } } }
private static void TestPt( TestConfig config, TextWriter tmpWriter, DirectoryInfo workDirectory, string activeDirectory, DirectoryInfo origTestDir) { //Delete generated files from previous PTester run: //<test>.cs, <test>.dll, <test>.pdb //foreach (var file in workDirectory.EnumerateFiles()) //{ // if (file.Extension == ".cs" || ((file.Extension == ".dll" || file.Extension == ".pdb") && file.Name == origTestDir.Name)) // { // file.Delete(); // } //} //Run CSharp compiler on generated .cs: // % 1: workDirectory // % 2: (origTestDir (test name) //csc.exe "%1\%2.cs" "%1\linker.cs" /debug /target:library /r:"D:\PLanguage\P\Bld\Drops\Debug\x86\Binaries\Prt.dll" /out:"%1\%2.dll" //string cscFilePath = "csc.exe"; string frameworkPath = RuntimeEnvironment.GetRuntimeDirectory(); string cscFilePath = Path.Combine(frameworkPath, "csc.exe"); if (!File.Exists(cscFilePath)) { throw new Exception("Could not find csc.exe"); } // Find .cs input to pt.exe: // pick up either .cs file with the name of origTestDir (if any), or // any .cs file in the workDirectory (but not linker.cs): string csFileName = null; foreach (FileInfo fileName in workDirectory.EnumerateFiles()) { if (fileName.Extension == ".cs" && Path .GetFileNameWithoutExtension(fileName.Name).ToLower().Equals(origTestDir.Name.ToLower()) || fileName.Extension == ".cs" && !Path.GetFileNameWithoutExtension(fileName.Name).Equals("linker")) { csFileName = fileName.FullName; } } //string csFileName = (from fileName in workDirectory.EnumerateFiles() // where fileName.Extension == ".cs" && (Path.GetFileNameWithoutExtension(fileName.Name)).Equals(origTestDir.Name)) // select fileName.FullName).FirstOrDefault(); //Debug: //if (!(csFileName == null)) // // Console.WriteLine(".cs input for pt.exe: {}", csFileName); //} if (csFileName == null) { throw new Exception("Could not find .cs input for pt.exe"); } // Find linker.cs: string linkerFileName = (from fileName1 in workDirectory.EnumerateFiles() where fileName1.Extension == ".cs" && Path.GetFileNameWithoutExtension(fileName1.Name).Equals("linker") select fileName1.FullName).FirstOrDefault(); //Debug: //if (!(linkerFileName == null)) //{ // Console.WriteLine("linker.cs input for pt.exe: {}", linkerFileName); //} if (linkerFileName == null) { throw new Exception("Could not find linker.cs input for pt.exe"); } // Find Prt.dll: string prtDllPath = Path.Combine( Constants.SolutionDirectory, "Bld", "Drops", Constants.Configuration, Constants.Platform, "Binaries", "Prt.dll"); //Debug: //Console.WriteLine("Prt.dll input for pt.exe: {}", prtDLLPath); if (!File.Exists(prtDllPath)) { throw new Exception("Could not find Prt.dll"); } // Output DLL file name: string outputDllName = origTestDir.Name + ".dll"; string outputDllPath = Path.Combine(workDirectory.FullName, outputDllName); //Debug: //Console.WriteLine("output DLL for csc.exe: {}", outputDLLPath); //Delete generated files from previous PTester run: //<test>.cs, <test>.dll, <test>.pdb, foreach (FileInfo file in workDirectory.EnumerateFiles()) { if (file.Name == origTestDir.Name && (file.Extension == ".dll" || file.Extension == ".pdb")) { file.Delete(); } } // Run C# compiler //IMPORTANT: since there's no way to suppress all warnings, if warnings other than specified below are detected, those would have to be added //Another option would be to not write csc.exe output into the acceptor at all //var arguments = new List<string>(config.Arguments) { "/debug", "/nowarn:1692,168,162", "/nologo", "/target:library", "/r:" + prtDLLPath, "/out:" + outputDLLPath, csFileName, linkerFileName }; var arguments = new List <string>(config.Arguments) { "/debug", "/target:library", "/r:" + prtDllPath, "/out:" + outputDllPath, csFileName, linkerFileName }; string stdout, stderr; int exitCode = ProcessHelper.RunWithOutput(cscFilePath, activeDirectory, arguments, out stdout, out stderr); //tmpWriter.Write(stdout); //tmpWriter.Write(stderr); tmpWriter.WriteLine($"EXIT (csc.exe): {exitCode}"); // Append includes foreach (string include in config.Includes) { tmpWriter.WriteLine(); tmpWriter.WriteLine("================================="); tmpWriter.WriteLine(include); tmpWriter.WriteLine("================================="); try { using (var sr = new StreamReader(Path.Combine(activeDirectory, include))) { while (!sr.EndOfStream) { tmpWriter.WriteLine(sr.ReadLine()); } } } catch (FileNotFoundException) { if (!include.EndsWith("trace")) { throw; } } } //Run pt.exe: pt.exe "%1\%2.dll" // Find pt.exe: string ptExePath = Path.Combine( Constants.SolutionDirectory, "Bld", "Drops", Constants.Configuration, Constants.Platform, "Binaries", "Pt.exe"); //Debug: //Console.WriteLine("Pt.exe input for pt.exe: {}", ptExePath); if (!File.Exists(ptExePath)) { throw new Exception("Could not find pt.exe"); } // input DLL file name: same as outputDLLPath // Run pt.exe arguments = new List <string>(config.Arguments) { outputDllPath }; int exitCode1 = ProcessHelper.RunWithOutput(ptExePath, activeDirectory, arguments, out stdout, out stderr); tmpWriter.Write(stdout); tmpWriter.Write(stderr); tmpWriter.WriteLine($"EXIT: {exitCode1}"); // Append includes foreach (string include in config.Includes) { tmpWriter.WriteLine(); tmpWriter.WriteLine("================================="); tmpWriter.WriteLine(include); tmpWriter.WriteLine("================================="); try { using (var sr = new StreamReader(Path.Combine(activeDirectory, include))) { while (!sr.EndOfStream) { tmpWriter.WriteLine(sr.ReadLine()); } } } catch (FileNotFoundException) { if (!include.EndsWith("trace")) { throw; } } } }