Search in sources :

Example 1 with GlobalTimeStoppingCondition

use of org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition in project evosuite by EvoSuite.

the class PropertiesTestGAFactory method getSearchAlgorithm.

@Override
public GeneticAlgorithm<TestChromosome> getSearchAlgorithm() {
    ChromosomeFactory<TestChromosome> factory = getChromosomeFactory();
    // FIXXME
    GeneticAlgorithm<TestChromosome> ga = getGeneticAlgorithm(factory);
    if (Properties.NEW_STATISTICS)
        ga.addListener(new org.evosuite.statistics.StatisticsListener());
    // How to select candidates for reproduction
    SelectionFunction<TestChromosome> selection_function = getSelectionFunction();
    selection_function.setMaximize(false);
    ga.setSelectionFunction(selection_function);
    // 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)) {
        ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
    }
    ga.resetStoppingConditions();
    ga.setPopulationLimit(getPopulationLimit());
    // How to cross over
    CrossOverFunction crossover_function = getCrossoverFunction();
    ga.setCrossOverFunction(crossover_function);
    if (Properties.CHECK_BEST_LENGTH) {
        org.evosuite.testcase.RelativeTestLengthBloatControl bloat_control = new org.evosuite.testcase.RelativeTestLengthBloatControl();
        ga.addBloatControl(bloat_control);
        ga.addListener(bloat_control);
    }
    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.RECYCLE_CHROMOSOMES) {
        if (Properties.STRATEGY == Strategy.ONEBRANCH)
            ga.addListener(TestCaseRecycler.getInstance());
    }
    // ga.addListener(new ResourceController<TestChromosome>());
    return ga;
}
Also used : ZeroFitnessStoppingCondition(org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition) MaxTimeStoppingCondition(org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition) CrossOverFunction(org.evosuite.ga.operators.crossover.CrossOverFunction) MutationTimeoutStoppingCondition(org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition) 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) TestChromosome(org.evosuite.testcase.TestChromosome) GlobalTimeStoppingCondition(org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition)

Example 2 with GlobalTimeStoppingCondition

use of org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition 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 3 with GlobalTimeStoppingCondition

use of org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition 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

MutationTimeoutStoppingCondition (org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition)3 CrossOverFunction (org.evosuite.ga.operators.crossover.CrossOverFunction)3 GlobalTimeStoppingCondition (org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition)3 MaxTimeStoppingCondition (org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition)3 StoppingCondition (org.evosuite.ga.stoppingconditions.StoppingCondition)3 ZeroFitnessStoppingCondition (org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition)3 ShutdownTestWriter (org.evosuite.ShutdownTestWriter)2 MutationTestPool (org.evosuite.coverage.mutation.MutationTestPool)2 RMIStoppingCondition (org.evosuite.ga.stoppingconditions.RMIStoppingCondition)2 SocketStoppingCondition (org.evosuite.ga.stoppingconditions.SocketStoppingCondition)2 StatisticsListener (org.evosuite.statistics.StatisticsListener)2 TestChromosome (org.evosuite.testcase.TestChromosome)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 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)1