Пример #1
0
Файл: Host.cs Проект: tupipa/vcc
        public static int Main(string[] args)
        {
            swTotal.Start();

            // reference symbol from Z3 so it gets copied
#pragma warning disable 168
            var y = new Microsoft.Boogie.SMTLib.Factory();
#pragma warning restore 168

            Logger.Instance.Register(ConsoleLogger.Instance);

            try
            {
                startTime                    = GetTime();
                cciErrorHandler              = new CciErrorHandler();
                dummyHostEnvironment.Errors += cciErrorHandler.HandleErrors;
                var commandLineOptions = OptionParser.ParseCommandLineArguments(dummyHostEnvironment, args);
                commandLineOptions.RunningFromCommandLine = true;
                cciErrorHandler.CommandLineOptions        = commandLineOptions;
                verificationErrorHandler = new VerificationErrorHandler(commandLineOptions);

                if (commandLineOptions.DisplayCommandLineHelp)
                {
                    DisplayCommandLineHelp();
                    return(0);
                }

                if (commandLineOptions.DisplayVersion)
                {
                    DisplayVersion();
                    return(0);
                }

                if (errorCount > 0 || fileErrorCount > 0)
                {
                    Console.Error.WriteLine("Exiting with 1 - error parsing arguments.");
                    return(1);
                }

                if (commandLineOptions.RunTestSuite)
                {
                    Logger.Instance.Unregister(ConsoleLogger.Instance);
                    Logger.Instance.Register(new ConsoleLoggerForTestRun());
                }

                if (!String.IsNullOrEmpty(commandLineOptions.XmlLogFile))
                {
                    Stream xmlStream = File.Open(commandLineOptions.XmlLogFile, FileMode.Create, FileAccess.Write);
                    Logger.Instance.Register(new XmlLogger(xmlStream));
                }

                if ((currentPlugin = InitializePlugin(commandLineOptions)) == null)
                {
                    Logger.Instance.Log("Exiting with 2 - error initializing plugin.");
                    return(2);
                }

                if (commandLineOptions.RunTestSuite)
                {
                    errorCount = TestRunner.RunTestSuite(commandLineOptions);
                }
                else
                {
                    RunPlugin(commandLineOptions);
                }

                swTotal.Stop();

                DumpTimes(commandLineOptions);

                int retVal = 0;

                if (errorCount > 0)
                {
                    Logger.Instance.Error("Exiting with 3 ({0} error(s).)", errorCount);
                    retVal = 3;
                }

                return(retVal);
            }
            finally
            {
                Logger.Instance.Dispose();
            }
        }
Пример #2
0
        public static int Main(string[] args)
        {
            Console.WriteLine("VCDryad ...");
              swTotal.Start();

              // reference symbol from Z3 so it gets copied
            #pragma warning disable 168
              var y = new Microsoft.Boogie.SMTLib.Factory();
            #pragma warning restore 168

              Logger.Instance.Register(ConsoleLogger.Instance);

              try
              {

              startTime = GetTime();
              cciErrorHandler = new CciErrorHandler();
              dummyHostEnvironment.Errors += cciErrorHandler.HandleErrors;
              var commandLineOptions = OptionParser.ParseCommandLineArguments(dummyHostEnvironment, args);
              commandLineOptions.RunningFromCommandLine = true;
              cciErrorHandler.CommandLineOptions = commandLineOptions;
              verificationErrorHandler = new VerificationErrorHandler(commandLineOptions);

              if (commandLineOptions.DisplayCommandLineHelp)
              {
              DisplayCommandLineHelp();
              return 0;
              }

              if (commandLineOptions.DisplayVersion)
              {
              DisplayVersion();
              return 0;
              }

              if (errorCount > 0 || fileErrorCount > 0)
              {
              Console.Error.WriteLine("Exiting with 1 - error parsing arguments.");
              return 1;
              }

              if (commandLineOptions.RunTestSuite) {
            Logger.Instance.Unregister(ConsoleLogger.Instance);
            Logger.Instance.Register(new ConsoleLoggerForTestRun());
              }

              if (!String.IsNullOrEmpty(commandLineOptions.XmlLogFile)) {
              Stream xmlStream = File.Open(commandLineOptions.XmlLogFile, FileMode.Create, FileAccess.Write);
              Logger.Instance.Register(new XmlLogger(xmlStream));
              }

              //Console.WriteLine("Initializing Dryad plugin ...");
              if ((currentPlugin = InitializePlugin(commandLineOptions)) == null)
              {
              Console.WriteLine("inside init plugin...");
              Logger.Instance.Log("Exiting with 2 - error initializing plugin.");
              return 2;
              }
              //Console.WriteLine("Done.");

              if (commandLineOptions.RunTestSuite)
              errorCount = TestRunner.RunTestSuite(commandLineOptions);
              else
              RunPlugin(commandLineOptions);

              swTotal.Stop();

              DumpTimes(commandLineOptions);

              int retVal = 0;

              if (errorCount > 0)
              {
              Logger.Instance.Error("Exiting with 3 ({0} error(s).)", errorCount);
              retVal = 3;
              }
              Console.WriteLine("VCDryad done.");
              return retVal;

              }
              finally
              {
              Logger.Instance.Dispose();
              }
        }
Пример #3
0
        private static int RunTest(CciErrorHandler errorHandler, string suiteName, string fileNameWithoutExt,
                               string test, VccOptions commandLineOptions, List<string> compilerParameters)
        {
            VccCommandLineHost.ResetErrorCount();
              string fileNameC = fileNameWithoutExt + ".c";
              string fileNameI = fileNameWithoutExt + ".i";

              StreamWriter tempStreamWriter = new StreamWriter(fileNameC);
              tempStreamWriter.Write(test);
              tempStreamWriter.Close();

              VccOptions options = new VccOptions();
              options.CopyFrom(commandLineOptions);

              if (compilerParameters != null)
            options = OptionParser.ParseCommandLineArguments(VccCommandLineHost.dummyHostEnvironment, compilerParameters, options);

              options.NoPreprocessor = false;
              options.CheckedArithmetic = true;
              options.RunTestSuite = true;
              options.FileNames = new List<string> { fileNameC };

              HostEnvironment hostEnvironment = new HostEnvironment(options.PointerSize);
              hostEnvironment.Errors += errorHandler.HandleErrors;

              bool errorsInPreprocessor;
              var f = CCompilerHelper.Preprocess(options, out errorsInPreprocessor);
              if (errorsInPreprocessor) return -1;
              var st = f.First();
              test = st.ReadToEnd();
              st.Close();
              File.Delete(fileNameC);
              // if (!options.KeepPreprocessorFiles) File.Delete(fileNameI);

              IName name = hostEnvironment.NameTable.GetNameFor(suiteName);
              List<IAssemblyReference> assemblyReferences = new List<IAssemblyReference>();
              List<IModuleReference> moduleReferences = new List<IModuleReference>();
              assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
              assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.VccRuntimeAssemblyIdentity));
              VccAssembly/*?*/ assem = null;
              if (hostEnvironment.previousDocument == null || compilerParameters == null ||
              !compilerParameters.Contains("/incremental"))
              {
            List<VccSourceDocument> programSources = new List<VccSourceDocument>(1);
            assem = new VccAssembly(name, "", hostEnvironment, options, assemblyReferences, moduleReferences, programSources);
            var helper = new VccCompilationHelper(assem.Compilation);
            programSources.Add(hostEnvironment.previousDocument = new VccSourceDocument(helper, name, name.ToString(), test));
              }
              VccCommandLineHost.ResetStartTime();
              return VccCommandLineHost.Felt2Cast2Plugin("testcase", options, hostEnvironment, assem);
        }
Пример #4
0
        static bool RunTestSuite(string directoryName, string suiteName, StreamReader instream, VccOptions commandLineOptions)
        {
            var startTime = DateTime.UtcNow;
              System.Diagnostics.Debug.Listeners.Remove("Default");
              var errorHandler = new CciErrorHandler(commandLineOptions);
              StringBuilder source = null;
              StringBuilder expectedOutput = null;
              StringBuilder actualOutput = null;
            int errors = 0;
              int testCaseCount = 0;
              var WhiteSpaceChars = " \r\n\t".ToCharArray();

              try {
            int line = 1;

            while (!instream.EndOfStream) {
              var l = instream.ReadLine(); // strips Unix or Dos line ending
              line++;

              source = new StringBuilder();
            List<string> compilerParameters;
            if (l.StartsWith("`") || l.StartsWith("//`")) {
            string optionString = l.Substring(l.IndexOf('`') + 1);
            compilerParameters = optionString.Split(WhiteSpaceChars, StringSplitOptions.RemoveEmptyEntries).ToList();
              } else {
            compilerParameters = new List<string>();
            source.Append(l);
            source.Append("\r\n");
              }

              while (!instream.EndOfStream) {
            l = instream.ReadLine();
            line++;
            if (l == "`" || l == "/*`")
              break;
            source.Append(l);
            source.Append("\r\n");
              }

              if (instream.EndOfStream) {
            Logger.Instance.Error("The last test case in the suite has not been provided with expected output");
            errors++;
            break;
              }

              int errLine = line;
              expectedOutput = new StringBuilder();
              while (!instream.EndOfStream) {
            l = instream.ReadLine();
            line++;
            if (l == "`" || l == "`*/")
              break;
            expectedOutput.Append(l);
            expectedOutput.Append("\r\n");
              }

              if (l != "`" && l != "`*/") {
            Logger.Instance.Error("The last test case in the suite has been provided with incomplete expected output");
            errors++;
            break;
              }

              actualOutput = new StringBuilder();
              TextWriter savedOut = Console.Out;
              Console.SetOut(new StringWriter(actualOutput));
              System.Diagnostics.TextWriterTraceListener myWriter = new System.Diagnostics.TextWriterTraceListener(System.Console.Out);
              System.Diagnostics.Debug.Listeners.Add(myWriter);

              ++testCaseCount;
              string suiteNameWithoutExt = Path.GetFileNameWithoutExtension(suiteName);
              string fileNameWithoutExt;

              if (commandLineOptions.OutputDir != null)
              {
              fileNameWithoutExt = commandLineOptions.OutputDir;
              }
              else
              {
              fileNameWithoutExt = directoryName;
              }

              fileNameWithoutExt += Path.DirectorySeparatorChar + suiteNameWithoutExt + vccSplitSuffix + testCaseCount + "_" + System.Diagnostics.Process.GetCurrentProcess().Id;
              currentTestcaseName = Path.GetFileName(string.Format("{0}.{1:00}", suiteNameWithoutExt, testCaseCount));

              try {
            int returnCode = RunTest(errorHandler, suiteNameWithoutExt, fileNameWithoutExt, source.ToString(), commandLineOptions, compilerParameters);
            if (returnCode < 0)
              actualOutput.Append("Non zero return code: " + returnCode);
              } catch (System.Reflection.TargetInvocationException e) {
            actualOutput.Append(e.InnerException);
              } catch (Exception e) {
            actualOutput.Append(e);
              }

              Logger.Instance.ResetReportedErrors();
              Console.SetOut(savedOut);
              System.Diagnostics.Debug.Listeners.Remove(myWriter);
              Regex rx = new Regex(@"[a-zA-Z]:\\.*?\\(.*)" + vccSplitSuffix + @"[0-9_]*.c\(");
              string actualOutputRepl = rx.Replace(actualOutput.ToString(), "testcase(");
              actualOutputRepl = actualOutputRepl.Trim();

              var expected = expectedOutput.ToString().Trim();
              if (!expected.Equals(actualOutputRepl)) {
            ReportError(suiteName, source, expected, actualOutputRepl, errLine, errors++ == 0);
              }

            }
            instream.Close();
            var runtime = DateTime.UtcNow.Subtract(startTime).TotalSeconds;
            if (errors == 0)
              Logger.Instance.Log("{0} passed [{1:0.00}]", suiteName, runtime);
            else {
              Logger.Instance.NewLine();
              Logger.Instance.Error("{0} had {1} failure(s) [{2:0.00}]", suiteName, errors, runtime);
            }
              } catch {
            var expected = expectedOutput == null ? "<none>" : expectedOutput.ToString().Trim();
            ReportError(suiteName, source, expected, actualOutput.ToString(), -1, true);
              }
              return errors == 0;
        }
Пример #5
0
        private static int RunTest(CciErrorHandler errorHandler, string suiteName, string fileNameWithoutExt,
                                   string test, VccOptions commandLineOptions, List <string> compilerParameters)
        {
            VccCommandLineHost.ResetErrorCount();
            string fileNameC = fileNameWithoutExt + ".c";
            string fileNameI = fileNameWithoutExt + ".i";

            StreamWriter tempStreamWriter = new StreamWriter(fileNameC);

            tempStreamWriter.Write(test);
            tempStreamWriter.Close();

            VccOptions options = new VccOptions();

            options.CopyFrom(commandLineOptions);

            if (compilerParameters != null)
            {
                options = OptionParser.ParseCommandLineArguments(VccCommandLineHost.dummyHostEnvironment, compilerParameters, options);
            }

            options.NoPreprocessor    = false;
            options.CheckedArithmetic = true;
            options.RunTestSuite      = true;
            options.FileNames         = new List <string> {
                fileNameC
            };

            HostEnvironment hostEnvironment = new HostEnvironment(options.PointerSize);

            hostEnvironment.Errors += errorHandler.HandleErrors;

            bool errorsInPreprocessor;
            var  f = CCompilerHelper.Preprocess(options, out errorsInPreprocessor);

            if (errorsInPreprocessor)
            {
                return(-1);
            }
            var st = f.First();

            test = st.ReadToEnd();
            st.Close();
            File.Delete(fileNameC);
            // if (!options.KeepPreprocessorFiles) File.Delete(fileNameI);

            IName name = hostEnvironment.NameTable.GetNameFor(suiteName);
            List <IAssemblyReference> assemblyReferences = new List <IAssemblyReference>();
            List <IModuleReference>   moduleReferences   = new List <IModuleReference>();

            assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
            assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.VccRuntimeAssemblyIdentity));
            VccAssembly /*?*/ assem = null;

            if (hostEnvironment.previousDocument == null || compilerParameters == null ||
                !compilerParameters.Contains("/incremental"))
            {
                List <VccSourceDocument> programSources = new List <VccSourceDocument>(1);
                assem = new VccAssembly(name, "", hostEnvironment, options, assemblyReferences, moduleReferences, programSources);
                var helper = new VccCompilationHelper(assem.Compilation);
                programSources.Add(hostEnvironment.previousDocument = new VccSourceDocument(helper, name, name.ToString(), test));
            }
            VccCommandLineHost.ResetStartTime();
            return(VccCommandLineHost.Felt2Cast2Plugin("testcase", options, hostEnvironment, assem));
        }
Пример #6
0
        static bool RunTestSuite(string directoryName, string suiteName, StreamReader instream, VccOptions commandLineOptions)
        {
            var startTime = DateTime.UtcNow;

            System.Diagnostics.Debug.Listeners.Remove("Default");
            var           errorHandler    = new CciErrorHandler(commandLineOptions);
            StringBuilder source          = null;
            StringBuilder expectedOutput  = null;
            StringBuilder actualOutput    = null;
            int           errors          = 0;
            int           testCaseCount   = 0;
            var           WhiteSpaceChars = " \r\n\t".ToCharArray();

            try {
                int line = 1;

                while (!instream.EndOfStream)
                {
                    var l = instream.ReadLine(); // strips Unix or Dos line ending
                    line++;

                    source = new StringBuilder();
                    List <string> compilerParameters;
                    if (l.StartsWith("`") || l.StartsWith("//`"))
                    {
                        string optionString = l.Substring(l.IndexOf('`') + 1);
                        compilerParameters = optionString.Split(WhiteSpaceChars, StringSplitOptions.RemoveEmptyEntries).ToList();
                    }
                    else
                    {
                        compilerParameters = new List <string>();
                        source.Append(l);
                        source.Append("\r\n");
                    }

                    while (!instream.EndOfStream)
                    {
                        l = instream.ReadLine();
                        line++;
                        if (l == "`" || l == "/*`")
                        {
                            break;
                        }
                        source.Append(l);
                        source.Append("\r\n");
                    }

                    if (instream.EndOfStream)
                    {
                        Logger.Instance.Error("The last test case in the suite has not been provided with expected output");
                        errors++;
                        break;
                    }

                    int errLine = line;
                    expectedOutput = new StringBuilder();
                    while (!instream.EndOfStream)
                    {
                        l = instream.ReadLine();
                        line++;
                        if (l == "`" || l == "`*/")
                        {
                            break;
                        }
                        expectedOutput.Append(l);
                        expectedOutput.Append("\r\n");
                    }

                    if (l != "`" && l != "`*/")
                    {
                        Logger.Instance.Error("The last test case in the suite has been provided with incomplete expected output");
                        errors++;
                        break;
                    }

                    actualOutput = new StringBuilder();
                    TextWriter savedOut = Console.Out;
                    Console.SetOut(new StringWriter(actualOutput));
                    System.Diagnostics.TextWriterTraceListener myWriter = new System.Diagnostics.TextWriterTraceListener(System.Console.Out);
                    System.Diagnostics.Debug.Listeners.Add(myWriter);

                    ++testCaseCount;
                    string suiteNameWithoutExt = Path.GetFileNameWithoutExtension(suiteName);
                    string fileNameWithoutExt;

                    if (commandLineOptions.OutputDir != null)
                    {
                        fileNameWithoutExt = commandLineOptions.OutputDir;
                    }
                    else
                    {
                        fileNameWithoutExt = directoryName;
                    }

                    fileNameWithoutExt += Path.DirectorySeparatorChar + suiteNameWithoutExt + vccSplitSuffix + testCaseCount + "_" + System.Diagnostics.Process.GetCurrentProcess().Id;
                    currentTestcaseName = Path.GetFileName(string.Format("{0}.{1:00}", suiteNameWithoutExt, testCaseCount));

                    try {
                        int returnCode = RunTest(errorHandler, suiteNameWithoutExt, fileNameWithoutExt, source.ToString(), commandLineOptions, compilerParameters);
                        if (returnCode < 0)
                        {
                            actualOutput.Append("Non zero return code: " + returnCode);
                        }
                    } catch (System.Reflection.TargetInvocationException e) {
                        actualOutput.Append(e.InnerException);
                    } catch (Exception e) {
                        actualOutput.Append(e);
                    }

                    Logger.Instance.ResetReportedErrors();
                    Console.SetOut(savedOut);
                    System.Diagnostics.Debug.Listeners.Remove(myWriter);
                    Regex  rx = new Regex(@"[a-zA-Z]:\\.*?\\(.*)" + vccSplitSuffix + @"[0-9_]*.c\(");
                    string actualOutputRepl = rx.Replace(actualOutput.ToString(), "testcase(");
                    actualOutputRepl = actualOutputRepl.Trim();

                    var expected = expectedOutput.ToString().Trim();
                    if (!expected.Equals(actualOutputRepl))
                    {
                        ReportError(suiteName, source, expected, actualOutputRepl, errLine, errors++ == 0);
                    }
                }
                instream.Close();
                var runtime = DateTime.UtcNow.Subtract(startTime).TotalSeconds;
                if (errors == 0)
                {
                    Logger.Instance.Log("{0} passed [{1:0.00}]", suiteName, runtime);
                }
                else
                {
                    Logger.Instance.NewLine();
                    Logger.Instance.Error("{0} had {1} failure(s) [{2:0.00}]", suiteName, errors, runtime);
                }
            } catch {
                var expected = expectedOutput == null ? "<none>" : expectedOutput.ToString().Trim();
                ReportError(suiteName, source, expected, actualOutput.ToString(), -1, true);
            }
            return(errors == 0);
        }