/// <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); }
private static void Main2(string[] args) { NLogConfigManager.CreateFileConfig(); Logger = NLog.LogManager.GetCurrentClassLogger(); if (args.Length != 1) { throw new InvalidUserParamsException( "RandoopBare takes exactly one argument but was " + "given the following arguments:" + System.Environment.NewLine + Util.PrintArray(args));; } // Parse XML file with generation parameters. string configFileName = ConfigFileName.Parse(args[0]); RandoopConfiguration config = LoadConfigFile(configFileName); // Set the random number generator. if (config.randomSource == RandomSource.SystemRandom) { Logger.Debug("Randoom seed = " + config.randomseed); SystemRandom random = new SystemRandom(); random.Init(config.randomseed); Enviroment.Random = random; } else { Util.Assert(config.randomSource == RandomSource.Crypto); Logger.Debug("Randoom seed = new System.Security.Cryptography.RNGCryptoServiceProvider()"); Enviroment.Random = new CryptoRandom(); } if (!Directory.Exists(config.outputdir)) { throw new InvalidUserParamsException("output directory does not exist: " + config.outputdir); } Collection <Assembly> assemblies = Misc.LoadAssemblies(config.assemblies); ////[email protected] for substituting MessageBox.Show() - start ////Instrument instrumentor = new Instrument(); //foreach (FileName asm in config.assemblies) //{ // Instrument.MethodInstrument(asm.fileName, "System.Windows.Forms.MessageBox::Show", "System.Logger.Debug"); //} ////[email protected] for substituting MessageBox.Show() - end IReflectionFilter filter1 = new VisibilityFilter(config); ConfigFilesFilter filter2 = new ConfigFilesFilter(config); Logger.Debug("========== REFLECTION PATTERNS:"); filter2.PrintFilter(Console.Out); IReflectionFilter filter = new ComposableFilter(filter1, filter2); Collection <Type> typesToExplore = ReflectionUtils.GetExplorableTypes(assemblies); PlanManager planManager = new PlanManager(config); planManager.builderPlans.AddEnumConstantsToPlanDB(typesToExplore); planManager.builderPlans.AddConstantsToTDB(config); Logger.Debug("========== INITIAL PRIMITIVE VALUES:"); planManager.builderPlans.PrintPrimitives(Console.Out); StatsManager stats = new StatsManager(config); Logger.Debug("Analyzing assembly."); ActionSet actions; try { actions = new ActionSet(typesToExplore, filter); } catch (EmpytActionSetException) { string msg = "After filtering based on configuration files, no remaining methods or constructors to explore."; throw new InvalidUserParamsException(msg); } Logger.Debug("Generating tests."); RandomExplorer explorer = new RandomExplorer(typesToExplore, filter, true, config.randomseed, config.arraymaxsize, stats, actions); ITimer t = new Timer(config.timelimit); try { explorer.Explore(t, planManager, config.methodweighing, config.forbidnull, true, config.fairOpt); } catch (Exception e) { Logger.Error("Explorer raised exception {0}", e.ToString()); throw; } }