Example #1
0
        static void Main(string[] args)
        {
            var seed      = args.Length > 1 ? Convert.ToInt32(args[0]) : int.MaxValue;
            var moves     = args.Length > 2 ? Convert.ToInt32(args[0]) : 10000;
            var maxPath   = args.Length > 3 ? Convert.ToInt32(args[1]) : 100;
            var map       = new Map.Map();
            var generator = new StraightPathGenerator(seed, map);
            var explorer  = new RandomExplorer(map, new List <Explorer.ILocationListener>()
            {
                generator
            });

            explorer.Explore(seed, moves);

            MapDrawer drawer = new MapDrawer();

            drawer.DrawMap(map);
            drawer.DrawPath(explorer.Path);
        }
Example #2
0
        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;
            }
        }