Search in sources :

Example 1 with RelativeSuiteLengthBloatControl

use of org.evosuite.testsuite.RelativeSuiteLengthBloatControl in project evosuite by EvoSuite.

the class PropertiesNoveltySearchFactory method getSearchAlgorithm.

@Override
public // public GeneticAlgorithm<TestChromosome> getSearchAlgorithm() {
NoveltySearch<TestChromosome> getSearchAlgorithm() {
    ChromosomeFactory<TestChromosome> factory = getChromosomeFactory();
    NoveltySearch<TestChromosome> ga = new NoveltySearch<>(factory);
    if (Properties.NEW_STATISTICS)
        ga.addListener(new StatisticsListener());
    // How to select candidates for reproduction
    SelectionFunction<TestChromosome> selectionFunction = getSelectionFunction();
    selectionFunction.setMaximize(false);
    ga.setSelectionFunction(selectionFunction);
    // When to stop the search
    StoppingCondition stopping_condition = getStoppingCondition();
    ga.setStoppingCondition(stopping_condition);
    // ga.addListener(stopping_condition);
    if (Properties.STOP_ZERO) {
        ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
    }
    if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
        ga.addStoppingCondition(new GlobalTimeStoppingCondition());
    }
    if (ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.STRONGMUTATION)) {
        if (Properties.STRATEGY == Properties.Strategy.ONEBRANCH)
            ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
        else
            ga.addListener(new MutationTestPool());
    // } else if (Properties.CRITERION == Criterion.DEFUSE) {
    // if (Properties.STRATEGY == Strategy.EVOSUITE)
    // ga.addListener(new DefUseTestPool());
    }
    ga.resetStoppingConditions();
    ga.setPopulationLimit(getPopulationLimit());
    // How to cross over
    CrossOverFunction crossover_function = getCrossoverFunction();
    ga.setCrossOverFunction(crossover_function);
    if (Properties.CHECK_BEST_LENGTH) {
        RelativeSuiteLengthBloatControl bloat_control = new org.evosuite.testsuite.RelativeSuiteLengthBloatControl();
        ga.addBloatControl(bloat_control);
        ga.addListener(bloat_control);
    }
    // ga.addBloatControl(new MaxLengthBloatControl());
    TestCaseSecondaryObjective.setSecondaryObjectives();
    if (Properties.DYNAMIC_LIMIT) {
        // max_s = GAProperties.generations * getBranches().size();
        // TODO: might want to make this dependent on the selected coverage
        // criterion
        // TODO also, question: is branchMap.size() really intended here?
        // I think BranchPool.getBranchCount() was intended
        Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
        stopping_condition.setLimit(Properties.SEARCH_BUDGET);
        logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
    }
    if (Properties.LOCAL_SEARCH_RESTORE_COVERAGE) {
        org.evosuite.ga.metaheuristics.SearchListener map = BranchCoverageMap.getInstance();
        ga.addListener(map);
    }
    if (Properties.SHUTDOWN_HOOK) {
        // ShutdownTestWriter writer = new
        // ShutdownTestWriter(Thread.currentThread());
        ShutdownTestWriter writer = new ShutdownTestWriter();
        ga.addStoppingCondition(writer);
        RMIStoppingCondition rmi = RMIStoppingCondition.getInstance();
        ga.addStoppingCondition(rmi);
        if (Properties.STOPPING_PORT != -1) {
            SocketStoppingCondition ss = new SocketStoppingCondition();
            ss.accept();
            ga.addStoppingCondition(ss);
        }
        // Runtime.getRuntime().addShutdownHook(writer);
        Signal.handle(new Signal("INT"), writer);
    }
    ga.addListener(new ResourceController());
    return ga;
}
Also used : ZeroFitnessStoppingCondition(org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition) MutationTestPool(org.evosuite.coverage.mutation.MutationTestPool) NoveltySearch(org.evosuite.ga.metaheuristics.NoveltySearch) StatisticsListener(org.evosuite.statistics.StatisticsListener) MaxTimeStoppingCondition(org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition) RelativeSuiteLengthBloatControl(org.evosuite.testsuite.RelativeSuiteLengthBloatControl) ShutdownTestWriter(org.evosuite.ShutdownTestWriter) CrossOverFunction(org.evosuite.ga.operators.crossover.CrossOverFunction) Signal(sun.misc.Signal) MutationTimeoutStoppingCondition(org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition) SocketStoppingCondition(org.evosuite.ga.stoppingconditions.SocketStoppingCondition) RMIStoppingCondition(org.evosuite.ga.stoppingconditions.RMIStoppingCondition) ZeroFitnessStoppingCondition(org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition) StoppingCondition(org.evosuite.ga.stoppingconditions.StoppingCondition) MaxTimeStoppingCondition(org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition) GlobalTimeStoppingCondition(org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition) MutationTimeoutStoppingCondition(org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition) SocketStoppingCondition(org.evosuite.ga.stoppingconditions.SocketStoppingCondition) ResourceController(org.evosuite.utils.ResourceController) RMIStoppingCondition(org.evosuite.ga.stoppingconditions.RMIStoppingCondition) TestChromosome(org.evosuite.testcase.TestChromosome) GlobalTimeStoppingCondition(org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition)

Example 2 with RelativeSuiteLengthBloatControl

use of org.evosuite.testsuite.RelativeSuiteLengthBloatControl in project evosuite by EvoSuite.

the class PropertiesSuiteGAFactory method getSearchAlgorithm.

@Override
public GeneticAlgorithm<TestSuiteChromosome> getSearchAlgorithm() {
    ChromosomeFactory<TestSuiteChromosome> factory = getChromosomeFactory();
    // FIXXME
    GeneticAlgorithm<TestSuiteChromosome> ga = getGeneticAlgorithm(factory);
    if (Properties.NEW_STATISTICS)
        ga.addListener(new StatisticsListener());
    // How to select candidates for reproduction
    SelectionFunction<TestSuiteChromosome> selectionFunction = getSelectionFunction();
    selectionFunction.setMaximize(false);
    ga.setSelectionFunction(selectionFunction);
    // When to stop the search
    StoppingCondition stopping_condition = getStoppingCondition();
    ga.setStoppingCondition(stopping_condition);
    // ga.addListener(stopping_condition);
    if (Properties.STOP_ZERO) {
        ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
    }
    if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
        ga.addStoppingCondition(new GlobalTimeStoppingCondition());
    }
    if (ArrayUtil.contains(Properties.CRITERION, Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Criterion.STRONGMUTATION)) {
        if (Properties.STRATEGY == Strategy.ONEBRANCH)
            ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
        else
            ga.addListener(new MutationTestPool());
    // } else if (Properties.CRITERION == Criterion.DEFUSE) {
    // if (Properties.STRATEGY == Strategy.EVOSUITE)
    // ga.addListener(new DefUseTestPool());
    }
    ga.resetStoppingConditions();
    ga.setPopulationLimit(getPopulationLimit());
    // How to cross over
    CrossOverFunction crossover_function = getCrossoverFunction();
    ga.setCrossOverFunction(crossover_function);
    if (Properties.CHECK_BEST_LENGTH) {
        RelativeSuiteLengthBloatControl bloat_control = new org.evosuite.testsuite.RelativeSuiteLengthBloatControl();
        ga.addBloatControl(bloat_control);
        ga.addListener(bloat_control);
    }
    // ga.addBloatControl(new MaxLengthBloatControl());
    TestSuiteSecondaryObjective.setSecondaryObjectives();
    if (Properties.DYNAMIC_LIMIT) {
        // max_s = GAProperties.generations * getBranches().size();
        // TODO: might want to make this dependent on the selected coverage
        // criterion
        // TODO also, question: is branchMap.size() really intended here?
        // I think BranchPool.getBranchCount() was intended
        Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
        stopping_condition.setLimit(Properties.SEARCH_BUDGET);
        logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
    }
    if (Properties.LOCAL_SEARCH_RESTORE_COVERAGE) {
        org.evosuite.ga.metaheuristics.SearchListener map = BranchCoverageMap.getInstance();
        ga.addListener(map);
    }
    if (Properties.SHUTDOWN_HOOK) {
        // ShutdownTestWriter writer = new
        // ShutdownTestWriter(Thread.currentThread());
        ShutdownTestWriter writer = new ShutdownTestWriter();
        ga.addStoppingCondition(writer);
        RMIStoppingCondition rmi = RMIStoppingCondition.getInstance();
        ga.addStoppingCondition(rmi);
        if (Properties.STOPPING_PORT != -1) {
            SocketStoppingCondition ss = new SocketStoppingCondition();
            ss.accept();
            ga.addStoppingCondition(ss);
        }
        // Runtime.getRuntime().addShutdownHook(writer);
        Signal.handle(new Signal("INT"), writer);
    }
    ga.addListener(new ResourceController());
    return ga;
}
Also used : ZeroFitnessStoppingCondition(org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition) MutationTestPool(org.evosuite.coverage.mutation.MutationTestPool) StatisticsListener(org.evosuite.statistics.StatisticsListener) MaxTimeStoppingCondition(org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition) RelativeSuiteLengthBloatControl(org.evosuite.testsuite.RelativeSuiteLengthBloatControl) org.evosuite.ga.metaheuristics(org.evosuite.ga.metaheuristics) ShutdownTestWriter(org.evosuite.ShutdownTestWriter) CrossOverFunction(org.evosuite.ga.operators.crossover.CrossOverFunction) Signal(sun.misc.Signal) MutationTimeoutStoppingCondition(org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition) SocketStoppingCondition(org.evosuite.ga.stoppingconditions.SocketStoppingCondition) ZeroFitnessStoppingCondition(org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition) StoppingCondition(org.evosuite.ga.stoppingconditions.StoppingCondition) MaxTimeStoppingCondition(org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition) RMIStoppingCondition(org.evosuite.ga.stoppingconditions.RMIStoppingCondition) GlobalTimeStoppingCondition(org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition) MutationTimeoutStoppingCondition(org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition) SocketStoppingCondition(org.evosuite.ga.stoppingconditions.SocketStoppingCondition) ResourceController(org.evosuite.utils.ResourceController) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) RMIStoppingCondition(org.evosuite.ga.stoppingconditions.RMIStoppingCondition) GlobalTimeStoppingCondition(org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition)

Aggregations

ShutdownTestWriter (org.evosuite.ShutdownTestWriter)2 MutationTestPool (org.evosuite.coverage.mutation.MutationTestPool)2 MutationTimeoutStoppingCondition (org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition)2 CrossOverFunction (org.evosuite.ga.operators.crossover.CrossOverFunction)2 GlobalTimeStoppingCondition (org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition)2 MaxTimeStoppingCondition (org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition)2 RMIStoppingCondition (org.evosuite.ga.stoppingconditions.RMIStoppingCondition)2 SocketStoppingCondition (org.evosuite.ga.stoppingconditions.SocketStoppingCondition)2 StoppingCondition (org.evosuite.ga.stoppingconditions.StoppingCondition)2 ZeroFitnessStoppingCondition (org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition)2 StatisticsListener (org.evosuite.statistics.StatisticsListener)2 RelativeSuiteLengthBloatControl (org.evosuite.testsuite.RelativeSuiteLengthBloatControl)2 ResourceController (org.evosuite.utils.ResourceController)2 Signal (sun.misc.Signal)2 org.evosuite.ga.metaheuristics (org.evosuite.ga.metaheuristics)1 NoveltySearch (org.evosuite.ga.metaheuristics.NoveltySearch)1 TestChromosome (org.evosuite.testcase.TestChromosome)1 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)1