Exemplo n.º 1
0
        public static int numDistinctContractViolPlans = 0; // counts the # of plans that violates contract (may violate same contract)

        public PlanManager(RandoopConfiguration config)
        {
            this.config         = config;
            this.builderPlans   = new PlanDataBase("builderPlans", config.typematchingmode);
            this.exceptionPlans = new PlanDataBase("exceptionThrowingPlans", config.typematchingmode);
            this.observerPlans  = new PlanDataBase("observerPlans", config.typematchingmode);

            Plan.uniqueIdCounter = config.planstartid;

            if (config.singledir)
            {
                this.testFileWriter = new SingleDirTestWriter(new DirectoryInfo(config.outputdir), config.testPrefix);
            }
            else
            {
                DirectoryInfo outputDir = new DirectoryInfo(config.outputdir);

                this.testFileWriter = new ClassifyingTestFileWriter(outputDir, config.testPrefix);
            }
        }
Exemplo n.º 2
0
        public ConfigFilesFilter(RandoopConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            Common.StringReader r = new StringReader();

            foreach (FileName path in config.forbid_typesFiles)
            {
                forbid_types.AddRange(r.Read(path.fileName));
            }

            foreach (FileName path in config.forbid_membersFiles)
            {
                forbid_members.AddRange(r.Read(path.fileName));
            }

            foreach (FileName path in config.forbid_fieldsFiles)
            {
                forbid_fields.AddRange(r.Read(path.fileName));
            }

            foreach (FileName path in config.require_typesFiles)
            {
                require_types.AddRange(r.Read(path.fileName));
            }

            foreach (FileName path in config.require_membersFiles)
            {
                require_members.AddRange(r.Read(path.fileName));
            }

            foreach (FileName path in config.require_fieldsFiles)
            {
                require_fields.AddRange(r.Read(path.fileName));
            }
        }
Exemplo n.º 3
0
        public static int numDistinctContractViolPlans = 0; // counts the # of plans that violates contract (may violate same contract)

        public PlanManager(RandoopConfiguration config)
        {
            this.config    = config;
            builderPlans   = new PlanDataBase("builderPlans", config.typematchingmode);
            exceptionPlans = new PlanDataBase("exceptionThrowingPlans", config.typematchingmode);
            observerPlans  = new PlanDataBase("observerPlans", config.typematchingmode);

            Plan.UniqueIdCounter = config.planstartid;

            switch (config.directoryStrategy)
            {
            case DirectoryStrategy.Single:
                testFileWriter = new SingleDirectoryTestFileWriter(new DirectoryInfo(config.outputdir), config.useRandoopContracts);
                break;

            case DirectoryStrategy.ClassifyingByBehavior:
                testFileWriter = new ClassifyingByBehaviorTestFileWriter(new DirectoryInfo(config.outputdir), config.useRandoopContracts);
                break;

            case DirectoryStrategy.ClassifyingByClass:
                testFileWriter = new ClassifyingByClassTestFileWriter(new DirectoryInfo(config.outputdir), config.useRandoopContracts);
                break;
            }
        }
Exemplo n.º 4
0
        public static RandoopConfiguration CreateConfigFile(
            CommandLineArguments args,
            string outputDirBase,
            int lastPlanId,
            TimeSpan timeForNextInvocation,
            int round,
            string executionLogFileName,
            int randomseed)
        {
            RandoopConfiguration config = new RandoopConfiguration();

            string statsFileName = outputDirBase + "\\" + Path.GetRandomFileName() + ".stats.txt";

            config.statsFile = new FileName(statsFileName);

            config.useRandoopContracts = args.UseRandoopContracts;
            Enum.TryParse(args.DirectoryStrategy, out DirectoryStrategy strategy);
            config.directoryStrategy  = strategy;
            config.outputnormalinputs = args.OutputNormal;
            config.outputdir          = outputDirBase;
            config.planstartid        = lastPlanId;
            config.timelimit          = Convert.ToInt32(timeForNextInvocation.TotalSeconds);
            config.randomseed         = round - 1 + randomseed;

            config.useinternal = args.ExploreInternal;
            config.usestatic   = !args.NoStatic;  // TODO fix this twisted logic!
            config.forbidnull  = !args.AllowNull; // TODO fix this twisted logic!
            config.fairOpt     = args.Fair;       // execute fair algorithm

            if (args.TrueRandom)
            {
                config.randomSource = RandomSource.Crypto;
            }
            else
            {
                config.randomSource = RandomSource.SystemRandom;
            }

            foreach (string s in args.AssemblyNames)
            {
                config.assemblies.Add(new FileName(new FileInfo(s).FullName));
            }
            config.executionLog = executionLogFileName;

            if (args.DontExecute)
            {
                config.executionmode = ExecutionMode.DontExecute;
            }

            // Load any configuration files present in the user-specified directory.

            bool userSpecifiedConfigDir = false;

            if (args.ConfigFilesDir != null)
            {
                if (Directory.Exists(args.ConfigFilesDir))
                {
                    userSpecifiedConfigDir = true;
                }
                else
                {
                    Logger.Debug("*** Warning: randoop could not find directory {0}.", args.ConfigFilesDir);
                    Logger.Debug("Will use default configuration files.");
                }
            }

            if (userSpecifiedConfigDir)
            {
                string configFile;

                configFile = args.ConfigFilesDir + @"\seed_sbyte.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.SbytesDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(sbyte), configFile));

                configFile = args.ConfigFilesDir + @"\seed_byte.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.BytesDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(byte), configFile));

                configFile = args.ConfigFilesDir + @"\seed_short.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.ShortsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(short), configFile));

                configFile = args.ConfigFilesDir + @"\seed_ushort.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.UshortsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(ushort), configFile));

                configFile = args.ConfigFilesDir + @"\seed_int.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.IntsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(int), configFile));

                configFile = args.ConfigFilesDir + @"\seed_uint.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.UintsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(uint), configFile));

                configFile = args.ConfigFilesDir + @"\seed_long.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.LongsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(long), configFile));

                configFile = args.ConfigFilesDir + @"\seed_ulong.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.UlongsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(ulong), configFile));

                configFile = args.ConfigFilesDir + @"\seed_char.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.CharsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(char), configFile));

                configFile = args.ConfigFilesDir + @"\seed_float.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.FloatsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(float), configFile));

                configFile = args.ConfigFilesDir + @"\seed_double.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.DoublesDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(double), configFile));

                configFile = args.ConfigFilesDir + @"\seed_bool.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.BoolsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(bool), configFile));

                configFile = args.ConfigFilesDir + @"\seed_decimal.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.DecimalsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(decimal), configFile));

                configFile = args.ConfigFilesDir + @"\seed_string.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.StringsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(string), configFile));

                configFile = args.ConfigFilesDir + @"\require_types.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.RequiretypesDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.require_typesFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = args.ConfigFilesDir + @"\require_members.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.RequiremembersDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.require_membersFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = args.ConfigFilesDir + @"\require_fields.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.RequirefieldsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.require_fieldsFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = args.ConfigFilesDir + @"\forbid_types.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.ForbidtypesDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.forbid_typesFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = args.ConfigFilesDir + @"\forbid_members.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.ForbidmembersDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.forbid_membersFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = args.ConfigFilesDir + @"\forbid_fields.txt";
                if (!File.Exists(configFile))
                {
                    configFile = Enviroment.ForbidfieldsDefaultConfigFile;
                }
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.forbid_fieldsFiles.Add(new FileName(new FileInfo(configFile).FullName));
            }
            else
            {
                string configFile;


                configFile = Enviroment.SbytesDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(sbyte), configFile));

                configFile = Enviroment.BytesDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(byte), configFile));

                configFile = Enviroment.ShortsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(short), configFile));

                configFile = Enviroment.UshortsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(ushort), configFile));

                configFile = Enviroment.IntsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(int), configFile));

                configFile = Enviroment.UintsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(uint), configFile));

                configFile = Enviroment.LongsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(long), configFile));

                configFile = Enviroment.UlongsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(ulong), configFile));

                configFile = Enviroment.CharsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(char), configFile));

                configFile = Enviroment.FloatsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(float), configFile));

                configFile = Enviroment.DoublesDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(double), configFile));

                configFile = Enviroment.BoolsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(bool), configFile));

                configFile = Enviroment.DecimalsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(decimal), configFile));

                configFile = Enviroment.StringsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.simpleTypeValues.Add(CreateSimpleValueTypeXmlElement(typeof(string), configFile));

                configFile = Enviroment.RequiretypesDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.require_typesFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = Enviroment.RequiremembersDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.require_membersFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = Enviroment.RequirefieldsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.require_fieldsFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = Enviroment.ForbidtypesDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.forbid_typesFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = Enviroment.ForbidmembersDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.forbid_membersFiles.Add(new FileName(new FileInfo(configFile).FullName));

                configFile = Enviroment.ForbidfieldsDefaultConfigFile;
                Logger.Debug("Will use configuration file {0}.", configFile);
                config.forbid_fieldsFiles.Add(new FileName(new FileInfo(configFile).FullName));
            }

            config.CheckRep();
            return(config);
        }
Exemplo n.º 5
0
 public VisibilityFilter(RandoopConfiguration env)
 {
     this.useStaticMethods = env.usestatic;
     this.useInternal      = env.useinternal;
 }
Exemplo n.º 6
0
        /// THE RETURN VALUE MEANS "PARAMETERS WRE OK"!!!!! BAD!!
        private static int DoInputGenerationRound(
            CommandLineArguments args,
            string outputDir,
            int round,
            ref TimeSpan totalTime,
            string tempDir,
            string executionLogFileName,
            int randomseed,
            Collection <string> methodsToOmit,
            Collection <string> constructorsToOmit)
        {
            // Calculate time for next invocation of Randoop.
            TimeSpan timeForNextInvocation = CalculateNextTimeLimit(args.TimeLimit, totalTime,
                                                                    new TimeSpan(0, 0, args.restartTimeSeconds));

            // Analyze last execution.
            int lastPlanId;

            AnalyzeLastExecution(executionLogFileName, out lastPlanId, outputDir);

            // Create a new randoop configuration.
            RandoopConfiguration config = ConfigFileCreator.CreateConfigFile(args, outputDir, lastPlanId,
                                                                             timeForNextInvocation, round, executionLogFileName, randomseed);

            string configFileName = tempDir + "\\config" + round + ".xml";

            config.Save(configFileName);
            FileInfo configFileInfo = new FileInfo(configFileName);

            // Launch new instance of Randoop.
            Console.WriteLine("------------------------------------");
            Console.WriteLine("Spawning new input generator process (round " + round + ")");

            Process p = new Process();

            p.StartInfo.FileName              = Enviroment.RandoopBareExe;
            p.StartInfo.Arguments             = ConfigFileName.ToString(configFileInfo);
            p.StartInfo.UseShellExecute       = false;
            p.StartInfo.ErrorDialog           = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow        = false;
            p.StartInfo.WorkingDirectory      = tempDir;


            Console.WriteLine("Spawning process: ");
            Console.WriteLine(Util.PrintProcess(p));

            // Give it 30 seconds to load reflection info, etc.
            int waitTime = (Convert.ToInt32(timeForNextInvocation.TotalSeconds) + 30) * 1000;

            Console.WriteLine("Will wait " + waitTime + " milliseconds for process to terminate.");

            p.Start();

            if (!p.WaitForExit(waitTime))
            {
                // Process didn't terminate. Kill it forcefully.
                Console.WriteLine("Killing process " + p.Id);
                try
                {
                    p.Kill();
                }
                catch (InvalidOperationException)
                {
                    // p has already terminated. No problem.
                }
                p.WaitForExit();
            }

            // Update total time.
            totalTime += p.ExitTime - p.StartTime;

            string err = p.StandardError.ReadToEnd();

            // Randoop terminated with error.
            if (p.ExitCode != 0)
            {
                if (err.Contains(Enviroment.RandoopBareInternalErrorMessage))
                {
                    Console.WriteLine(err);
                    Console.WriteLine("*** RandoopBare had an internal error. Exiting.");
                    return(p.ExitCode);
                }

                if (err.Contains(Enviroment.RandoopBareInvalidUserParametersErrorMessage))
                {
                    Console.WriteLine(err);
                    Console.WriteLine("*** RandoopBare terminated normally. Exiting.");
                    return(p.ExitCode);
                }
            }

            return(0);
        }
Exemplo n.º 7
0
        // Add some non-zero constants to the mix.
        public void AddConstantsToTDB(RandoopConfiguration config)
        {
            foreach (SimpleTypeValues vs in config.simpleTypeValues)
            {
                Type type = Type.GetType(vs.simpleType);

                if (type == null)
                {
                    throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                }

                foreach (FileName fn in vs.fileNames)
                {
                    string fileName = fn.fileName;
                    if (!File.Exists(fileName))
                    {
                        throw new Common.RandoopBareExceptions.InvalidUserParamsException("Configuration file does not exist: " + fileName);
                    }

                    if (type.Equals(typeof(sbyte)))
                    {
                        SByteReader r = new SByteReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(sbyte), o));
                        }
                    }
                    else if (type.Equals(typeof(byte)))
                    {
                        ByteReader r = new ByteReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(byte), o));
                        }
                    }
                    else if (type.Equals(typeof(short)))
                    {
                        ShortReader r = new ShortReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(short), o));
                        }
                    }
                    else if (type.Equals(typeof(ushort)))
                    {
                        UshortReader r = new UshortReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(ushort), o));
                        }
                    }
                    else if (type.Equals(typeof(int)))
                    {
                        IntReader r = new IntReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(int), o));
                        }
                    }
                    else if (type.Equals(typeof(uint)))
                    {
                        UintReader r = new UintReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(uint), o));
                        }
                    }
                    else if (type.Equals(typeof(long)))
                    {
                        LongReader r = new LongReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(long), o));
                        }
                    }
                    else if (type.Equals(typeof(ulong)))
                    {
                        UlongReader r = new UlongReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(ulong), o));
                        }
                    }
                    else if (type.Equals(typeof(char)))
                    {
                        CharReader r = new CharReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(char), o));
                        }
                    }
                    else if (type.Equals(typeof(float)))
                    {
                        FloatReader r = new FloatReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(float), o));
                        }
                    }
                    else if (type.Equals(typeof(double)))
                    {
                        DoubleReader r = new DoubleReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(double), o));
                        }
                    }
                    else if (type.Equals(typeof(bool)))
                    {
                        BoolReader r = new BoolReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(bool), o));
                        }
                    }
                    else if (type.Equals(typeof(decimal)))
                    {
                        DecimalReader r = new DecimalReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(decimal), o));
                        }
                    }
                    else
                    {
                        if (!type.Equals(typeof(string)))
                        {
                            throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                        }
                        Common.StringReader r = new Common.StringReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(string), o));
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
 public StatsManager(RandoopConfiguration config)
 {
     this.writer = new StreamWriter(config.statsFile.fileName);
     this.state  = StatKind.Start;
 }