コード例 #1
0
ファイル: AbsDiff.cs プロジェクト: asvishnyakov/CodeContracts
    static void Main(string[] args)
    {
      // Parse the options
      var options = new Options(args);
      if (options.Error != null)
      {
        Console.WriteLine(options.Error);
        Environment.Exit(-1);
      }

      // Check the existence of the files
      string error;
      string[] outputFileNames;
      if (!CheckFiles(options, out outputFileNames, out error))
      {
        Console.WriteLine(error);
        Environment.Exit(-1);
      }

      Contract.Assert(outputFileNames.Length == 2);

      // Launch the two analyses
      var success= new bool[2];
      Parallel.For(0, 2,  i => RunProcess(options, outputFileNames, i, success));

      // Now run the diff, if success
      if (success[0] && success[1])
      {
        AbsDiffMain(options, outputFileNames);
      }
    }
コード例 #2
0
ファイル: AbsDiff.cs プロジェクト: asvishnyakov/CodeContracts
    private static void AbsDiffMain(Options options, string[] outputFileNames)
    {
      Contract.Requires(outputFileNames.Length == 2);

      if (options.DiffPre)
      {
        RunAbsDiff(outputFileNames[0], outputFileNames[1], "-pre");
      }
      if (options.DiffPost)
      {
        RunAbsDiff(outputFileNames[0], outputFileNames[1], "-post");
      }
      if (options.DiffInv)
      {
        RunAbsDiff(outputFileNames[0], outputFileNames[1], "-inv");
      }
      if (options.DiffAssume)
      {
        RunAbsDiff(outputFileNames[0], outputFileNames[1], "-assume");
      }
    }
コード例 #3
0
ファイル: AbsDiff.cs プロジェクト: asvishnyakov/CodeContracts
 private static string CreateClousotCMD(Options options, int i)
 {
   var platform = Environment.GetEnvironmentVariable("SystemRoot") + Platform;
   var customOptions = String.Join(" ", options.ClousotOptions);
   return String.Join(" ", "-platform", platform, ClousotDefaultArguments, customOptions, options.File[i]);
 }
コード例 #4
0
ファイル: AbsDiff.cs プロジェクト: asvishnyakov/CodeContracts
    static bool CheckFiles(Options options, out string[] OutputFileName, out string errorMsg)
    {
      Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out OutputFileName).Length == 2);
      OutputFileName = new string[2];

      for (var i = 0; i < 2; i++)
      {
        if (!File.Exists(options.File[i]))
        {
          errorMsg = options.File[i] + ErrorMessages.FileNotExists;
          OutputFileName = null;
          return false;
        }
        else
        {
          OutputFileName[i] = options.File[i] + PrettyPrint(File.GetLastWriteTime(options.File[i])) + ".txt";
        }
      }

      if (!ExistsExeInThePath(PerlExe))
      {
        errorMsg = ErrorMessages.MissingPerlEXE;
        return false;
      }

      if (!File.Exists(PerlScript))
      {
        errorMsg = ErrorMessages.MissingPerlScript;
        return false;
      }

      foreach (var exe in ClousotExes)
      {
        var path = options.CCCheckDir + exe;
        if (File.Exists(path))
        {
          ClousotExe = path;
          errorMsg = null;
          return true;
        }
      }
      errorMsg = ErrorMessages.CCCheckNotFound;
      return false;
    }
コード例 #5
0
ファイル: AbsDiff.cs プロジェクト: asvishnyakov/CodeContracts
    private static void RunProcess(Options options, string[] outputFileNames, int i, bool[] success)
    {
      Contract.Requires(options != null);

      var start = DateTime.Now;

      var processStartInfo = new ProcessStartInfo();
      processStartInfo.FileName = ClousotExe;
      processStartInfo.Arguments = CreateClousotCMD(options, i);
#if SAMEWINDOW
      processStartInfo.UseShellExecute = false;
      processStartInfo.RedirectStandardOutput = true;
      processStartInfo.RedirectStandardError = true;
#else
      processStartInfo.Arguments += " > " + outputFileNames[i];
      processStartInfo.UseShellExecute = true;
      processStartInfo.RedirectStandardOutput = false;
      processStartInfo.RedirectStandardError = false;

#endif
      Console.WriteLine("#{0}: Starting the analysis of {1}", i, options.File[i]);
      if (options.Trace)
      {
        Console.WriteLine("     Command line : {0}", processStartInfo.Arguments);
      }
      using (var process = Process.Start(processStartInfo))
      {
#if SAMEWINDOW
        //process.BeginOutputReadLine();
        using (var stdio = process.StandardOutput)
        {
          var result = stdio.ReadToEnd();
          File.AppendAllText(outputFileNames[i], result);
          //Console.WriteLine(result);
          success[i] = true;
        }
        using (var stderr = process.StandardError)
        {
          var result = stderr.ReadToEnd();
          if (!String.IsNullOrEmpty(result))
          {
            Console.WriteLine("*** Error in the analysis of " + options.File[i]);
            Console.WriteLine(result);
            success[i] = false;
          }
        }
#endif
        success[i] = process.ExitCode == 0;
      }
     
      Console.WriteLine("#{0}: Done analysis of {1} (success? {2})", i, options.File[i], success[i]);
      Console.WriteLine("      Result wrote in  {0}. Elapsed {1}", outputFileNames[i], DateTime.Now - start);
    }