Exemplo n.º 1
0
        /// <summary>
        /// Main randoop entrypoint.
        /// </summary>
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("Randoop.NET: an API fuzzer for .Net. Version {0} (compiled {1}).",
                              Common.Enviroment.RandoopVersion, Common.Enviroment.RandoopCompileDate);

            if (args.Length == 0 || IsHelpCommand(args[0]))
            {
                Console.Error.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(1);
            }

            if (ContainsHelp(args))
            {
                Console.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(0);
            }

            if (args[0].Equals("/about"))
            {
                WriteAboutMessageToConsole();
                System.Environment.Exit(0);
            }

            if (args[0].Equals("minimize"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.Minimize(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                Collection <FileInfo> oldTests = TestCaseUtils.CollectFilesEndingWith(".cs", args2);
                Console.WriteLine("Number of original tests: " + oldTests.Count);
                Collection <FileInfo> newTests = TestCaseUtils.Reduce(oldTests);
                Console.WriteLine("Number of reduced tests: " + newTests.Count);
                Dictionary <TestCase.ExceptionDescription, Collection <FileInfo> > classifiedTests =
                    TestCaseUtils.ClassifyTestsByMessage(newTests);
                PrintStats(classifiedTests);
                StringBuilder b = new StringBuilder();
                foreach (string s in args)
                {
                    b.Append(" " + s);
                }
                string htmlFileName = "reduced" + Path.GetRandomFileName() + ".html";
                HtmlSummary.CreateIndexHtml(classifiedTests, htmlFileName, b.ToString());
                OpenExplorer(htmlFileName);
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reproduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.ReproduceBehavior(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].StartsWith("stats:"))
            {
                string statsResultsFileName = args[0].Substring("stats:".Length);

                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);

                StatsManager.ComputeStats(statsResultsFileName,
                                          TestCaseUtils.CollectFilesEndingWith(".stats.txt", args2));
                System.Environment.Exit(0);
            }

            GenerateTests(args);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Main randoop entrypoint.
        /// </summary>
        static void Main(string[] args)
        {
            NLogConfigManager.CreateFileConfig();
            Console.WriteLine("Randoop.NET: an API fuzzer for .Net. Version {0} (compiled {1}).",
                              Enviroment.RandoopVersion, Enviroment.RandoopCompileDate);

            if (args.Length == 0 || IsHelpCommand(args[0]))
            {
                Console.Error.WriteLine(HelpScreen.Usagestring());
                Environment.Exit(1);
            }

            if (ContainsHelp(args))
            {
                Console.WriteLine(HelpScreen.Usagestring());
                Environment.Exit(0);
            }

            if (args[0].Equals("/about"))
            {
                WriteAboutMessageToConsole();
                Environment.Exit(0);
            }

            //[email protected] adds "RandoopMappedCalls"
            if (args[0].Equals("methodtransformer"))
            {
                string   mapfile = args[1];
                string[] args2   = new string[args.Length - 2];
                Array.Copy(args, 2, args2, 0, args.Length - 2);
                Dictionary <string, string> methodmapper = new Dictionary <string, string>();

                try
                {
                    Instrument.ParseMapFile(mapfile, ref methodmapper); //parse a file that defines the mapping between target method and replacement method

                    foreach (string asm in args2)
                    {
                        int      mapcnt      = methodmapper.Count;
                        string[] origmethods = new string[mapcnt];
                        methodmapper.Keys.CopyTo(origmethods, 0);
                        foreach (string src in origmethods)
                        {
                            Instrument.MethodInstrument(asm, src, methodmapper[src]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Environment.Exit(-1);
                }

                Environment.Exit(0);
            }

            if (args[0].Equals("minimize"))
            {
                HandleMinimization(args);
            }

            if (args[0].Equals("reduce"))
            {
                HandleReduction(args, EquivalenceBasedReducer.Reduce);
            }

            if (args[0].Equals("reduce2"))
            {
                HandleReduction(args, SequenceBasedReducer.Reduce);
            }

            if (args[0].Equals("reproduce"))
            {
                HandleReproduction(args);
            }

            if (args[0].StartsWith("stats:"))
            {
                string statsResultsFileName = args[0].Substring("stats:".Length);

                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);

                StatsManager.ComputeStats(statsResultsFileName,
                                          TestCaseUtils.CollectFilesEndingWith(".stats.txt", args2));
                Environment.Exit(0);
            }

            GenerateTests(args);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Main randoop entrypoint.
        /// </summary>
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("Randoop.NET: an API fuzzer for .Net. Version {0} (compiled {1}).",
                              Common.Enviroment.RandoopVersion, Common.Enviroment.RandoopCompileDate);

            if (args.Length == 0 || IsHelpCommand(args[0]))
            {
                Console.Error.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(1);
            }

            if (ContainsHelp(args))
            {
                Console.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(0);
            }

            if (args[0].Equals("/about"))
            {
                WriteAboutMessageToConsole();
                System.Environment.Exit(0);
            }

            //[email protected] adds "RandoopMappedCalls"
            if (args[0].Equals("methodtransformer"))
            {
                string   mapfile = args[1];
                string[] args2   = new string[args.Length - 2];
                Array.Copy(args, 2, args2, 0, args.Length - 2);
                Dictionary <string, string> methodmapper = new Dictionary <string, string>();

                try
                {
                    Instrument.ParseMapFile(mapfile, ref methodmapper); //parse a file that defines the mapping between target method and replacement method

                    foreach (string asm in args2)
                    {
                        int       mapcnt      = methodmapper.Count;
                        string [] origmethods = new string [mapcnt];
                        methodmapper.Keys.CopyTo(origmethods, 0);
                        foreach (string src in origmethods)
                        {
                            Instrument.MethodInstrument(asm, src, methodmapper[src]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    System.Environment.Exit(-1);
                }

                System.Environment.Exit(0);
            }
            //[email protected] adds "RandoopMappedCalls"

            if (args[0].Equals("minimize"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.Minimize(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                Collection <FileInfo> oldTests = TestCaseUtils.CollectFilesEndingWith(".cs", args2);
                Console.WriteLine("Number of original tests: " + oldTests.Count);
                Collection <FileInfo> newTests = TestCaseUtils.Reduce(oldTests);
                Console.WriteLine("Number of reduced tests: " + newTests.Count);
                //Dictionary<TestCase.ExceptionDescription, Collection<FileInfo>> classifiedTests =
                //    TestCaseUtils.ClassifyTestsByMessage(newTests);
                //PrintStats(classifiedTests);
                //StringBuilder b = new StringBuilder();
                //foreach (string s in args) b.Append(" " + s);
                //string htmlFileName = "reduced" + Path.GetRandomFileName() + ".html";
                ////HtmlSummary.CreateIndexHtml(classifiedTests, htmlFileName, b.ToString());
                //HtmlSummary.CreateIndexHtml2(classifiedTests, htmlFileName, b.ToString());
                //OpenExplorer(htmlFileName);
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reduce2")) //[email protected] adds for sequence-based reduction
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                Collection <FileInfo> oldTests = TestCaseUtils.CollectFilesEndingWith(".cs", args2);
                Console.WriteLine("Number of original tests: " + oldTests.Count);
                Collection <FileInfo> newTests = TestCaseUtils.Reduce2(oldTests);
                Console.WriteLine("Number of reduced tests: " + newTests.Count);
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reproduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.ReproduceBehavior(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].StartsWith("stats:"))
            {
                string statsResultsFileName = args[0].Substring("stats:".Length);

                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);

                StatsManager.ComputeStats(statsResultsFileName,
                                          TestCaseUtils.CollectFilesEndingWith(".stats.txt", args2));
                System.Environment.Exit(0);
            }

            GenerateTests(args);
        }