Esempio n. 1
0
        private static int RunProcess(string cwd, string tool, string arguments, Output output, string writeBatchFile = null)
        {
            ProcessStartInfo i = new ProcessStartInfo(tool, arguments);
            output.WriteLine("Running '{0}'", i.FileName);
            output.WriteLine("         {0}", i.Arguments);
            i.RedirectStandardOutput = true;
            i.RedirectStandardError = true;
            i.UseShellExecute = false;
            i.CreateNoWindow = true;
            i.WorkingDirectory = cwd;
            i.ErrorDialog = false;
            if (writeBatchFile != null)
            {
                var file = new StreamWriter(Path.Combine(cwd, writeBatchFile + ".bat"));
                file.WriteLine("\"{0}\" {1} %1 %2 %3 %4 %5", i.FileName, i.Arguments);
                file.Close();
            }

            using (Process p = Process.Start(i))
            {
                p.OutputDataReceived += output.OutputDataReceivedEventHandler;
                p.ErrorDataReceived += output.ErrDataReceivedEventHandler;
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();

                Assert.True(p.WaitForExit(200000), string.Format("{0} timed out", i.FileName));
                if (p.ExitCode != 0)
                {
                    Assert.Equal(0, p.ExitCode);
                }
                return p.ExitCode;
            }
        }
Esempio n. 2
0
        public static Output Ignore(ITestOutputHelper testOutputHelper)
        {
            if (ignore == null)
                ignore = new Output(testOutputHelper, "Ignore");

            return ignore;
        }
Esempio n. 3
0
 internal static void Clousot1Slicing(string absoluteSourceDir, string absoluteBinary, Options options, Output output)
 {
     var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework));
     var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework));
     var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary);
     var absoluteSource = absoluteBinary;
     var libPathsString = FormLibPaths(contractreferencedir, options) + " /libpaths:.";
     var args = String.Format("{0} -cci1 /regression /define:cci1only;clousot1 -framework:{4} -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString, options.Framework);
     if (options.Fast || System.Diagnostics.Debugger.IsAttached)
     {
         output.WriteLine("Calling NewCCI2Driver.Main with: {0}", args);
         // Use output to avoid Clousot from closing the Console
         Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.NewCCI2Driver.Main(args.Split(' '), output));
     }
     else
         RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2SlicingExe), args, output);
 }
Esempio n. 4
0
        internal static void Clousot(string absoluteSourceDir, string absoluteBinary, Options options, string testName, int testindex, Output output)
        {
            var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework));
            var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework));
            var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary);
            var absoluteSource = absoluteBinary;
            var libPathsString = FormLibPaths(contractreferencedir, options);
            var args = string.Format("{0} /regression /define:cci1only;clousot1 -framework:{4} -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString, options.Framework);

            WriteRSPFile(absoluteBinaryDir, testName, args);
            
            if (options.Fast || Debugger.IsAttached)
            {
                output.WriteLine("Calling CCI1Driver.Main with: {0}", args);
                // Use output to avoid Clousot from closing the Console
                Assert.Equal(0, Microsoft.Research.CodeAnalysis.CCI1Driver.Main(args.Split(' '), output));
            }
            else
            {
                RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(ClousotExe), args, output, testName);
            }
        }
Esempio n. 5
0
 private void ActionAsIsolated(Options options, out Exception exceptionThrown, out string dataReceived)
 {
   using (var stringWriter = new StringWriter())
   {
     var output = new Output(String.Format("Isolated::{0}", options.TestName), stringWriter);
     exceptionThrown = null;
     try
     {
       this.action(options, output);
     }
     catch (Exception e)
     {
       exceptionThrown = e;
     }
     dataReceived = stringWriter.ToString();
   }
 }
Esempio n. 6
0
 public static Tuple<Output, StringWriter> ConsoleOutputFor(ITestOutputHelper testOutputHelper, string name)
 {
     StringWriter writer = new StringWriter();
     Output output = new Output(testOutputHelper, String.Format("Console::{0}", name), writer);
     return Tuple.Create(output, writer);
 }
Esempio n. 7
0
        internal static void Clousot2Slicing(string absoluteSourceDir, string absoluteBinary, Options options, Output output)
        {
            var referencedir         = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework));
            var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework));
            var absoluteBinaryDir    = Path.GetDirectoryName(absoluteBinary);
            var absoluteSource       = absoluteBinary;
            var libPathsString       = FormLibPaths(contractreferencedir, options) + " /libpaths:.";
            var args = String.Format("{0} /show progress  /regression /define:cci2only;clousot2 -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString);

            if (options.Fast || System.Diagnostics.Debugger.IsAttached)
            {
                output.WriteLine("Calling NewCCI2Driver.Main with: {0}", args);
                // Use output to avoid Clousot2 from closing the Console
                Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.NewCCI2Driver.Main(args.Split(' '), output));
            }
            else
            {
                RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2SlicingExe), args, output);
            }
        }
Esempio n. 8
0
        private static Process StartServiceProcess(string cwd, string tool, string arguments, Output output, string writeBatchFile = null)
        {
            ProcessStartInfo i = new ProcessStartInfo(tool, arguments);

            output.WriteLine("Running '{0}'", i.FileName);
            output.WriteLine("         {0}", i.Arguments);
            i.RedirectStandardInput  = true;
            i.RedirectStandardOutput = true;
            i.RedirectStandardError  = true;
            i.UseShellExecute        = false;
            i.CreateNoWindow         = true;
            i.WorkingDirectory       = cwd;
            i.ErrorDialog            = false;
            if (writeBatchFile != null)
            {
                var file = new StreamWriter(Path.Combine(cwd, writeBatchFile + ".bat"));
                file.WriteLine("\"{0}\" {1} %1 %2 %3 %4 %5", i.FileName, i.Arguments);
                file.Close();
            }

            var p = Process.Start(i);

            p.OutputDataReceived += output.OutputDataReceivedEventHandler;
            p.ErrorDataReceived  += output.ErrDataReceivedEventHandler;
            p.BeginOutputReadLine();
            p.BeginErrorReadLine();

            Assert.IsFalse(p.WaitForExit(1000), "{0} exited too quickly", i.FileName);

            return(p);
        }
Esempio n. 9
0
 public static void BuildAndAnalyze1Slicing(Options options)
 {
     BuildAndAnalyze1Slicing(options, Output.ConsoleOutputFor(options.TestName));
 }
Esempio n. 10
0
        private static Process StartServiceProcess(string cwd, string tool, string arguments, Output output, string writeBatchFile = null)
        {
            ProcessStartInfo i = new ProcessStartInfo(tool, arguments);
            output.WriteLine("Running '{0}'", i.FileName);
            output.WriteLine("         {0}", i.Arguments);
            i.RedirectStandardInput = true;
            i.RedirectStandardOutput = true;
            i.RedirectStandardError = true;
            i.UseShellExecute = false;
            i.CreateNoWindow = true;
            i.WorkingDirectory = cwd;
            i.ErrorDialog = false;
            if (writeBatchFile != null)
            {
                var file = new StreamWriter(Path.Combine(cwd, writeBatchFile + ".bat"));
                file.WriteLine("\"{0}\" {1} %1 %2 %3 %4 %5", i.FileName, i.Arguments);
                file.Close();
            }

            var p = Process.Start(i);

            p.OutputDataReceived += output.OutputDataReceivedEventHandler;
            p.ErrorDataReceived += output.ErrDataReceivedEventHandler;
            p.BeginOutputReadLine();
            p.BeginErrorReadLine();

            Assert.IsFalse(p.WaitForExit(1000), "{0} exited too quickly", i.FileName);

            return p;
        }
Esempio n. 11
0
        private static void BuildAndAnalyze2Slicing(Options options, Output output)
        {
            string absoluteSourceDir;
            var target = Build(options, "/d:CLOUSOT2 /d:SLICING", output, out absoluteSourceDir);

            if (target != null)
                Clousot2Slicing(absoluteSourceDir, target, options, output);
        }
Esempio n. 12
0
        internal static string Build(Options options, string extraCompilerOptions, Output output, out string absoluteSourceDir)
        {
            var sourceFile = options.MakeAbsolute(options.SourceFile);
            var compilerpath = options.MakeAbsolute(Path.Combine(ToolsRoot, options.BuildFramework, options.Compiler));
            var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.BuildFramework));
            var sourcedir = absoluteSourceDir = Path.GetDirectoryName(sourceFile);
            var outputdir = Path.Combine(sourcedir, "bin", options.BuildFramework);
            var extension = options.UseExe ? ".exe" : ".dll";
            var targetKind = options.UseExe ? "exe" : "library";
            var suffix = "_" + options.TestInstance;
            if (options.GenerateUniqueOutputName)
                suffix += "." + randGenerator.Next(0x10000).ToString("X4"); // enables concurrent tests on the same source file
            var targetfile = Path.Combine(outputdir, Path.GetFileNameWithoutExtension(sourceFile) + suffix + extension);
            // add Microsoft.Contracts reference if needed
            if (!options.BuildFramework.Contains("v4."))
            {
                options.References.Add("Microsoft.Contracts.dll");
            }

            // MB: do not modify the CurrentDirectory, that could cause parallel tests to fail

            var resolvedReferences = ResolveReferences(options);
            var referenceString = ReferenceOptions(resolvedReferences);
            if (!Directory.Exists(outputdir))
            {
                Directory.CreateDirectory(outputdir);
            }
            var args = String.Format("/debug /t:{4} /out:{0} {5} {3} {2} {1}", targetfile, sourceFile, referenceString, options.CompilerOptions(resolvedReferences), targetKind, extraCompilerOptions);
            var exitCode = RunProcess(sourcedir, compilerpath, args, output);
            if (exitCode != 0)
            {
                return null;
            }
            //CopyReferenceAssemblies(resolvedReferences, outputdir);

            return targetfile;
        }
Esempio n. 13
0
        private static void BuildAndAnalyze2S(ITestOutputHelper testOutputHelper, Options options, Output output)
        {
            string absoluteSourceDir;
            var target = Build(options, "/d:CLOUSOT2", output, out absoluteSourceDir);

            if (target != null)
                Clousot2S(testOutputHelper, absoluteSourceDir, target, options, output);
        }