Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Coupled branches Calculator module #116

Merged
merged 40 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
66321c7
rename and repackage the guided single objective GA
Nov 15, 2019
0d289b9
Add Test length fitnes function
Nov 18, 2019
25b9307
Add NSGA-II for sum scalarization + test len objectives
Nov 18, 2019
b31e686
Update testLen fitness function
Nov 22, 2019
a8b52f7
Initialize coupled branches calculator module
Dec 5, 2019
b677f71
Implement executor
Dec 5, 2019
4c6e4e4
Implement customized instrumentation
Dec 5, 2019
b4ac4c5
Fix a minor bug in branch pair equal
Dec 6, 2019
a7e2a62
Set caller and callee by input parameters
Dec 6, 2019
e947076
Collect branch pairs using Cling libraries
Dec 6, 2019
9e91bd7
Add shading
Dec 7, 2019
cdc8472
Collect executionTraces in the pool
Dec 7, 2019
3eea31f
Remove unused classes
Dec 7, 2019
a1f3a74
Collect the covered coupled branches
Dec 7, 2019
04e7093
Handle checkstyle violations
Dec 7, 2019
195f7f0
Update gitignore to ignore local directory in CBC test
Dec 7, 2019
b1fb6fd
Adapt tool to accept two test suites (TestE and TestR)
Dec 9, 2019
8b642ab
Merge branch 'master' into CoupledBranches
Dec 13, 2019
b466ddf
update CBC calculator CommandLineParameters to calculate CBC for a si…
Feb 17, 2020
abc48e5
Fix a bug in static initialization
Feb 17, 2020
e299843
Fix a minor issue in logging
Feb 17, 2020
8daf1c1
Update CBC executor
Feb 26, 2020
a4012c6
Change single test suite input parameter name
Feb 26, 2020
24ef6ab
Fix a bug in CBC calculator
Feb 26, 2020
9d8d2d9
Print covered coupled branches
Feb 26, 2020
c4c94f2
Fix some minor bugs in MOSA algorithm
Mar 3, 2020
24c3e5c
Save testSuite object in Cling
Mar 3, 2020
7161cd7
Fix a bug in getCoverageGoals for Coupled branches
Mar 3, 2020
4052b5c
Fix a minor issue in logging
Mar 3, 2020
e172c47
Remove unused imports
Mar 3, 2020
dc1497c
Merge branch 'master' into CoupledBranches
Mar 3, 2020
beeba7c
Exclude independent paths pool for test coverage
Mar 3, 2020
03920e5
Merge remote-tracking branch 'origin/CoupledBranches' into CoupledBra…
Mar 3, 2020
3d20afa
Add a test suite for caller in botsing-examples
Mar 3, 2020
a36c242
Clean some classes of CBC calculator for testing
Mar 3, 2020
2ff7690
Write some tests for CBC calculator
Mar 3, 2020
3a31096
Test PostProcessUtility in botsing commons
Mar 4, 2020
275c76b
Remove useless input parameters
Mar 4, 2020
b9b3688
Add coupledBranches test suite for CBC
Mar 4, 2020
7dcd9fa
Add System-level tests for CBC
Mar 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Thumbs.db
**/test/**/botsing/model/generation/local/
**/test/**/cling/local/
**/test/**/coupling/analyze/local/
**/test/**/cbc/local/


# Generated website
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PostProcessUtility {
private static final Logger LOG = LoggerFactory.getLogger(PostProcessUtility.class);

public static void postProcessTests(TestSuiteChromosome testSuite, List<TestFitnessFactory<? extends TestFitnessFunction>> fitnessFactories) {

LOG.info("test size before post-process: {}",testSuite.size());
if (Properties.INLINE) {
ConstantInliner inliner = new ConstantInliner();
inliner.inline(testSuite);
Expand All @@ -49,6 +49,7 @@ public static void postProcessTests(TestSuiteChromosome testSuite, List<TestFitn
throw new Error("EvoSuite bug: minimization lead fitness from " + before + " to " + after);
}
}
LOG.info("test size after post-process: {}",testSuite.size());

if (Properties.ASSERTIONS) {
LOG.info("Generating assertions");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class AbstractMOSA<T extends Chromosome> extends org.evosuite.ga.metaheur
private static final Logger LOG = LoggerFactory.getLogger(AbstractMOSA.class);
protected Mutation<T> mutation;

/** Boolean vector to indicate whether each test goal is covered or not. **/
protected Set<FitnessFunction<T>> uncoveredGoals = new LinkedHashSet<FitnessFunction<T>>();
protected Set<FitnessFunction<T>> coveredGoals = new LinkedHashSet<FitnessFunction<T>>();

/** Map used to store the covered test goals (keys of the map) and the corresponding covering test cases (values of the map) **/
protected Map<FitnessFunction<T>, T> archive = new LinkedHashMap<FitnessFunction<T>, T>();
FitnessFunctions fitnessCollector;
Expand Down Expand Up @@ -131,7 +135,14 @@ protected void evolve() {}
@Override
public void generateSolution() {}

@Override
protected Set<FitnessFunction<T>> getCoveredGoals() {
return this.coveredGoals;
}


@Override
protected Set<FitnessFunction<T>> getUncoveredGoals() {
return this.uncoveredGoals;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public class MOSA<T extends Chromosome> extends AbstractMOSA<T> {
private static final Logger LOG = LoggerFactory.getLogger(MOSA.class);


/** Boolean vector to indicate whether each test goal is covered or not. **/
protected Set<FitnessFunction<T>> uncoveredGoals = new LinkedHashSet<FitnessFunction<T>>();


protected CrowdingDistance<T> distance = new CrowdingDistance<T>();

Expand Down Expand Up @@ -134,7 +133,7 @@ public void generateSolution() {
// Calculate dominance ranks and crowding distance
this.rankingFunction.computeRankingAssignment(this.population, this.uncoveredGoals);
for (int i = 0; i < this.rankingFunction.getNumberOfSubfronts(); i++) {
this.distance.fastEpsilonDominanceAssignment(this.rankingFunction.getSubfront(i), this.getUncoveredGoals());
this.distance.fastEpsilonDominanceAssignment(this.rankingFunction.getSubfront(i), this.uncoveredGoals);
}


Expand All @@ -149,6 +148,7 @@ public void generateSolution() {
for(StoppingCondition stoppingCondition : this.stoppingConditions){
if(stoppingCondition.isFinished()){
LOG.info("Stopping reason: {}", stoppingCondition.toString());
LOG.info("Number of covered goals are: {}", this.coveredGoals.size());
}

}
Expand Down Expand Up @@ -210,6 +210,7 @@ private void updateArchive(T solution, FitnessFunction<T> covered) {
} else {
archive.put(covered, solution);
this.uncoveredGoals.remove(covered);
this.coveredGoals.add(covered);
LOG.debug("New covered goal: {}",covered);
}
}
Expand Down Expand Up @@ -297,4 +298,11 @@ protected int getNumberOfCoveredGoals() {
LOG.debug("# Covered Goals = " + n_covered_goals);
return n_covered_goals;
}

@Override
protected List<T> getNonDominatedSolutions(List<T> solutions) {
return super.getNonDominatedSolutions(solutions);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package eu.stamp.botsing.commons;

import org.evosuite.Properties;
import org.evosuite.coverage.TestFitnessFactory;
import org.evosuite.result.TestGenerationResult;
import org.evosuite.setup.TestCluster;
import org.evosuite.testcase.TestChromosome;
import org.evosuite.testcase.TestFitnessFunction;
import org.evosuite.testcase.factories.AllMethodsTestChromosomeFactory;
import org.evosuite.testsuite.TestSuiteChromosome;
import org.evosuite.utils.generic.GenericClass;
import org.evosuite.utils.generic.GenericMethod;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.lang.reflect.Method;
import java.util.ArrayList;

import static eu.stamp.botsing.commons.PostProcessUtility.writeJUnitFailingTests;
import static eu.stamp.botsing.commons.PostProcessUtility.writeJUnitTestsAndCreateResult;


public class PostProcessUtilityTest {

private TestSuiteChromosome testSuite;

@Before
public void generateTestSuite() throws NoSuchMethodException {
Object obj = new String();
GenericClass gc = Mockito.mock(GenericClass.class);
Mockito.when(gc.hasWildcardOrTypeVariables()).thenReturn(false);
Method m = obj.getClass().getMethod("equals", Object.class);
GenericMethod call = Mockito.mock(GenericMethod.class,Mockito.RETURNS_DEEP_STUBS);
Mockito.doReturn(obj.getClass()).when(call).getDeclaringClass();
Mockito.when(call.getName()).thenReturn("equals");
Mockito.when(call.getOwnerClass()).thenReturn(gc);
Mockito.when(call.isMethod()).thenReturn(true);
Mockito.when(call.getOwnerType()).thenReturn(String.class);
Mockito.when(call.getMethod()).thenReturn(m);
Mockito.when(call.getParameterTypes()).thenReturn(m.getParameterTypes());
Mockito.when(call.getReturnType()).thenReturn(Boolean.TYPE);
Mockito.when(call.isPublic()).thenReturn(true);
Mockito.doReturn(boolean.class).when(call).getRawGeneratedType();


Mockito.when(call.copy()).thenReturn(call);
TestCluster.getInstance().addTestCall(call);

AllMethodsTestChromosomeFactory testChromosomeFactory = new AllMethodsTestChromosomeFactory();
TestChromosome test =testChromosomeFactory.getChromosome();
testSuite = new TestSuiteChromosome();
testSuite.addTest(test);
}

@Test
public void testWithoutSearchObjective(){
TestFitnessFactory testFitnessFactory = Mockito.mock(TestFitnessFactory.class);
ArrayList testFitnessFactoryList = new ArrayList();
testFitnessFactoryList.add(testFitnessFactory);
PostProcessUtility.postProcessTests(testSuite, testFitnessFactoryList);
// Minimization suppose to remove the test because there is no search objective
assert(testSuite.getTests().size() == 0);
}

@Test
public void testWithSearchObjective(){
TestFitnessFunction testFF = Mockito.mock(TestFitnessFunction.class);
Mockito.when(testFF.isCovered(testSuite.getTestChromosome(0))).thenReturn(true);
ArrayList<TestFitnessFunction> coverageGoals = new ArrayList<>();
coverageGoals.add(testFF);

Properties.MINIMIZE = false;
TestFitnessFactory testFitnessFactory = Mockito.mock(TestFitnessFactory.class);
Mockito.when(testFitnessFactory.getCoverageGoals()).thenReturn(coverageGoals);
Mockito.when(testFitnessFactory.getCoverageGoals()).thenReturn(coverageGoals);
ArrayList testFitnessFactoryList = new ArrayList();
testFitnessFactoryList.add(testFitnessFactory);
PostProcessUtility.postProcessTests(testSuite, testFitnessFactoryList);
assert(testSuite.getTests().size() == 1);
}

@Test
public void testWriteTest(){
TestGenerationResult writingTest = writeJUnitTestsAndCreateResult(testSuite, Properties.JUNIT_SUFFIX);
String interestingPart = writingTest.getTestSuiteCode().split("public void test0\\(\\) throws Throwable \\{\n")[1];
interestingPart = interestingPart.replaceAll(" ","");
assert (interestingPart.startsWith(testSuite.getTests().get(0).toCode()));

writeJUnitFailingTests();

Properties.CHECK_CONTRACTS = true;
writeJUnitFailingTests();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package eu.stamp.botsing.coupling;

import org.junit.Test;

public class CallerTest {

@Test
public void test0(){
Caller caller = new Caller(10,20);
caller.firstNumberIsBigger();
}
}
Binary file modified botsing-reproduction/evosuite-client-botsing-1.1.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public enum TestGenerationStrategy {
public enum FitnessFunction {
WeightedSum,
SimpleSum,
TestLen,
IntegrationIndexedAccess,
IntegrationSingleObjective;
FitnessFunction() {
Expand All @@ -77,6 +78,7 @@ public enum FitnessFunction {
public enum SearchAlgorithm {
Single_Objective_GGA,
Guided_MOSA,
NSGA_II,
DynaMOSA;

SearchAlgorithm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,21 @@ private TestFitnessFunction getFF(CrashProperties.FitnessFunction givenFFName, S
return new IntegrationTestingFF(crash);
case IntegrationIndexedAccess:
return new ITFFForIndexedAccess(crash);
case TestLen:
return new TestLenFF();
default:
return new WeightedSum(crash);
}
}


public static double normalize(double value) throws IllegalArgumentException {
if (value < 0d) {
throw new IllegalArgumentException("Values to normalize cannot be negative");
}
if (Double.isInfinite(value)) {
return 1.0;
}
return value / (1.0 + value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package eu.stamp.botsing.fitnessfunction;

import org.evosuite.testcase.TestChromosome;
import org.evosuite.testcase.TestFitnessFunction;
import org.evosuite.testcase.execution.ExecutionResult;

public class TestLenFF extends TestFitnessFunction {
@Override
public double getFitness(TestChromosome testChromosome, ExecutionResult executionResult) {
double testLen = testChromosome.getTestCase().size();
// 1 - Normalize(len)
return (1 - FitnessFunctionHelper.normalize(testLen));
}

@Override
public int compareTo(TestFitnessFunction other) {
if (other == null){
return 1;
}

if (other instanceof TestLenFF){
return 0;
}

return compareClassName(other);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
return prime * result + (this.getClass().hashCode());
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
return getClass() == obj.getClass();
}

@Override
public String getTargetClass() {
return null;
}

@Override
public String getTargetMethod() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,16 @@ public double getFitness(TestChromosome testChromosome, ExecutionResult executio
}

@Override
public int compareTo(TestFitnessFunction testFitnessFunction) {
// TODO Add this when we have multple fitness functions
return 0;
public int compareTo(TestFitnessFunction other) {
if (other == null){
return 1;
}

if (other instanceof WeightedSum){
return 0;
}

return compareClassName(other);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.evosuite.testcase.execution.MethodCall;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static eu.stamp.botsing.fitnessfunction.FitnessFunctionHelper.normalize;

import java.util.*;

Expand Down Expand Up @@ -258,18 +259,4 @@ private List<BranchCoverageTestFitness> setupDependencies(String className , Str
return branchCoverages;
}


private double normalize(double value) throws IllegalArgumentException {
if (value < 0d) {
throw new IllegalArgumentException("Values to normalize cannot be negative");
}
if (Double.isInfinite(value)) {
return 1.0;
}
return value / (1.0 + value);
}




}
Loading