public BatchExeResult Execute(string filename, out string expected, out string current) { BatchExeResult result = BatchExeResult.SolcError; string filePath = Path.Combine(testDirectory, filename); // compile the program SolidityCompiler compiler = new SolidityCompiler(); CompilerOutput compilerOutput = compiler.Compile(solcPath, filePath); if (compilerOutput.ContainsError()) { compilerOutput.PrintErrorsToConsole(); throw new SystemException("Compilation Error"); } // build the Solidity AST from solc output AST solidityAST = new AST(compilerOutput, Path.GetDirectoryName(filePath)); // translate Solidity to Boogie try { BoogieTranslator translator = new BoogieTranslator(); var translatorFlags = new TranslatorFlags(); translatorFlags.GenerateInlineAttributes = false; BoogieAST boogieAST = translator.Translate(solidityAST, new HashSet <Tuple <string, string> >(), translatorFlags); // dump the Boogie program to a file using (var outWriter = new StreamWriter(outFile)) { outWriter.WriteLine(boogieAST.GetRoot()); } } catch (Exception e) { Console.WriteLine($"VeriSol translation error: {e.Message}"); result = BatchExeResult.SolToBoogieError; expected = current = null; return(result); } // read the corral configuration from Json string configJsonPath = Path.Combine(configDirectory, Path.GetFileNameWithoutExtension(filename) + ".json"); string jsonString = File.ReadAllText(configJsonPath); CorralConfiguration corralConfig = JsonConvert.DeserializeObject <CorralConfiguration>(jsonString); string corralOutput = RunCorral(corralConfig); expected = corralConfig.ExpectedResult; current = corralOutput; result = CompareCorralOutput(corralConfig.ExpectedResult, corralOutput); return(result); }
public bool BatchExecute() { string[] filePaths = Directory.GetFiles(testDirectory); int passedCount = 0; int failedCount = 0; ReadRecord(); foreach (string filePath in filePaths) { string filename = Path.GetFileName(filePath); if (!filename.StartsWith(testPrefix)) { continue; } //silently ignore non .sol files if (!filename.EndsWith(".sol")) { continue; } if (!filesToRun.ContainsKey(filename)) { logger.LogWarning($"{filename} not found in {Path.Combine(recordsDir, "records.txt")}"); continue; } if (!filesToRun[filename]) { continue; } logger.LogInformation($"Running {filename}"); BatchExeResult batchExeResult = BatchExeResult.SolcError; string expectedCorralOutput = "", currentCorralOutput = ""; try { batchExeResult = Execute(filename, out expectedCorralOutput, out currentCorralOutput); } catch (Exception exception) { logger.LogCritical(exception, $"Exception occurred in {filename}"); batchExeResult = BatchExeResult.OtherException; } if (batchExeResult == BatchExeResult.Success) { ++passedCount; logger.LogInformation($"Passed - {filename}"); } else if (batchExeResult == BatchExeResult.SolcError) { ++failedCount; logger.LogError($"Failed (Solc failed) - {filename}"); } else if (batchExeResult == BatchExeResult.OtherException) { ++failedCount; logger.LogError($"Failed (Other exception) - {filename}"); } else if (batchExeResult == BatchExeResult.SolToBoogieError) { ++failedCount; logger.LogError($"Failed (VeriSol translation error) - {filename}"); } else if (batchExeResult == BatchExeResult.CorralError) { ++failedCount; logger.LogError($"Failed (Corral regression failed) - {filename}"); logger.LogError($"\t Expected - {expectedCorralOutput}"); logger.LogError($"\t Corral detailed Output - {currentCorralOutput}"); } else { ++failedCount; logger.LogError($"Failed (Tool error: unexpected failure code) - {filename}"); } } logger.LogInformation($"{passedCount} passed {failedCount} failed"); DeleteTemporaryFiles(); return(failedCount == 0); }