Skip to content

Commit a985b48

Browse files
author
Pouria Derakhshanfar
authored
Merge pull request #111 from CoolTomatos/indexedAccess
ITFFForArrayIndex now works with indexed String access as well.
2 parents fb37364 + 7b253dc commit a985b48

8 files changed

Lines changed: 49 additions & 47 deletions

File tree

-105 KB
Binary file not shown.

botsing-reproduction/src/main/java/eu/stamp/botsing/CrashProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public enum TestGenerationStrategy {
6868
public enum FitnessFunction {
6969
WeightedSum,
7070
SimpleSum,
71-
IntegrationArrayIndex,
71+
IntegrationIndexedAccess,
7272
IntegrationSingleObjective;
7373
FitnessFunction() {
7474
}

botsing-reproduction/src/main/java/eu/stamp/botsing/StackTrace.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ public void setup(String logPath, int frameLevel) throws IllegalArgumentExceptio
100100
LOG.info("Target Class is set to: " + targetClass);
101101

102102
// If the target exception is ArrayIndexOutOfBoundsException
103-
if (exceptionType.equals(ArrayIndexOutOfBoundsException.class.getName())) {
103+
if (exceptionType.equals(ArrayIndexOutOfBoundsException.class.getName()) || exceptionType.equals(StringIndexOutOfBoundsException.class.getName())) {
104104
// Set the line number where the array access call is located at.
105-
Properties.TARGET_ARRAY_LINE = frames.get(0).getLineNumber();
105+
Properties.TARGET_INDEXED_ACCESS_LINE = frames.get(0).getLineNumber();
106106
// Set the fitness function for this crash to be the customized one.
107107
CrashProperties.fitnessFunctions[CrashProperties.getInstance().getCrashesSize() - 1] =
108-
CrashProperties.FitnessFunction.IntegrationArrayIndex;
108+
CrashProperties.FitnessFunction.IntegrationIndexedAccess;
109109
}
110110
} catch (FileNotFoundException e) {
111111
LOG.debug("Stack trace file not found!", e);

botsing-reproduction/src/main/java/eu/stamp/botsing/fitnessfunction/FitnessFunctionHelper.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,56 +28,55 @@
2828

2929
public class FitnessFunctionHelper {
3030

31-
public boolean isConstructor(BytecodeInstruction targetInstruction){
31+
public boolean isConstructor(BytecodeInstruction targetInstruction) {
3232
String methodName = targetInstruction.getMethodName();
3333
methodName = methodName.substring(0, methodName.indexOf('('));
3434
String classPath = targetInstruction.getClassName();
3535
int lastOccurrence = classPath.lastIndexOf(".");
36-
if (lastOccurrence == -1){
36+
if (lastOccurrence == -1) {
3737
return false;
3838
}
39-
String className = classPath.substring(lastOccurrence+1);
39+
String className = classPath.substring(lastOccurrence + 1);
4040
return className.equals(methodName);
41-
4241
}
4342

44-
public TestFitnessFunction getSingleObjective(){
45-
return getFF(CrashProperties.fitnessFunctions[0],CrashProperties.getInstance().getStackTrace(0));
43+
public TestFitnessFunction getSingleObjective() {
44+
return getFF(CrashProperties.fitnessFunctions[0], CrashProperties.getInstance().getStackTrace(0));
4645
}
47-
public TestFitnessFunction[] getMultiObjectives(){
48-
if(CrashProperties.fitnessFunctions.length > 1){
46+
47+
public TestFitnessFunction[] getMultiObjectives() {
48+
if (CrashProperties.fitnessFunctions.length > 1) {
4949
// Here, we have 1 crash and multiple fitness functions
50-
TestFitnessFunction[] result = new TestFitnessFunction[CrashProperties.fitnessFunctions.length];
50+
TestFitnessFunction[] result = new TestFitnessFunction[CrashProperties.fitnessFunctions.length];
5151
StackTrace singleCrash = CrashProperties.getInstance().getStackTrace(0);
52-
for (int i = 0; i<CrashProperties.fitnessFunctions.length;i++){
53-
result[i] = getFF(CrashProperties.fitnessFunctions[i],singleCrash);
52+
for (int i = 0; i < CrashProperties.fitnessFunctions.length; i++) {
53+
result[i] = getFF(CrashProperties.fitnessFunctions[i], singleCrash);
5454
}
5555
return result;
56-
}else if(CrashProperties.getInstance().getCrashesSize() > 1){
56+
} else if (CrashProperties.getInstance().getCrashesSize() > 1) {
5757
// Here, we have multiple crashes and 1 fitness function
5858
int numberOfCrashes = CrashProperties.getInstance().getCrashesSize();
59-
TestFitnessFunction[] result = new TestFitnessFunction[numberOfCrashes];
60-
for (int i = 0; i<numberOfCrashes;i++){
61-
result[i]= getFF(CrashProperties.fitnessFunctions[0],CrashProperties.getInstance().getStackTrace(i));
59+
TestFitnessFunction[] result = new TestFitnessFunction[numberOfCrashes];
60+
for (int i = 0; i < numberOfCrashes; i++) {
61+
result[i] = getFF(CrashProperties.fitnessFunctions[0], CrashProperties.getInstance().getStackTrace(i));
6262
}
6363
return result;
64-
}else{
65-
throw new IllegalStateException("Number of crashes and fitness functions are 1. Botsing cannot use a multi-objective algorithm");
64+
} else {
65+
throw new IllegalStateException("Number of crashes and fitness functions are 1. Botsing cannot use a " +
66+
"multi-objective algorithm");
6667
}
6768
}
6869

69-
private TestFitnessFunction getFF(CrashProperties.FitnessFunction givenFFName, StackTrace crash){
70-
switch (givenFFName){
70+
private TestFitnessFunction getFF(CrashProperties.FitnessFunction givenFFName, StackTrace crash) {
71+
switch (givenFFName) {
7172
case WeightedSum:
7273
return new WeightedSum(crash);
7374
case IntegrationSingleObjective:
7475
return new IntegrationTestingFF(crash);
75-
case IntegrationArrayIndex:
76-
return new ITFFForArrayIndex(crash);
76+
case IntegrationIndexedAccess:
77+
return new ITFFForIndexedAccess(crash);
7778
default:
7879
return new WeightedSum(crash);
7980
}
8081
}
81-
82-
8382
}

botsing-reproduction/src/main/java/eu/stamp/botsing/fitnessfunction/ITFFForArrayIndex.java renamed to botsing-reproduction/src/main/java/eu/stamp/botsing/fitnessfunction/ITFFForIndexedAccess.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77

8-
import java.util.Map;
8+
import java.util.Set;
99

10-
public class ITFFForArrayIndex extends IntegrationTestingFF {
11-
private static final Logger logger = LoggerFactory.getLogger(ITFFForArrayIndex.class);
10+
public class ITFFForIndexedAccess extends IntegrationTestingFF {
11+
private static final Logger logger = LoggerFactory.getLogger(ITFFForIndexedAccess.class);
1212

13-
public ITFFForArrayIndex(StackTrace crash) {
13+
public ITFFForIndexedAccess(StackTrace crash) {
1414
super(crash);
1515
}
1616

@@ -19,16 +19,17 @@ protected double exceptionCoverage(ExecutionResult executionResult) {
1919
if (super.exceptionCoverage(executionResult) == 0) {
2020
return 0;
2121
}
22-
Map<Integer, int[]> arrayAccessInfo = executionResult.getTrace().getArrayAccessInfo();
23-
if (arrayAccessInfo.isEmpty()) {
24-
return 1;
22+
double exceptionCoverage = 1;
23+
Set<int[]> indexedAccessInfo = executionResult.getTrace().getIndexedAccessInfo();
24+
if (indexedAccessInfo.isEmpty()) {
25+
return exceptionCoverage;
2526
}
26-
double exceptionCoverage = 0;
27-
for (Map.Entry<Integer, int[]> entry : arrayAccessInfo.entrySet()) {
28-
int[] indexAndLength = entry.getValue();
29-
exceptionCoverage += distance(indexAndLength[0], indexAndLength[1]);
27+
28+
for (int[] pair : indexedAccessInfo) {
29+
double distance = distance(pair[0], pair[1]);
30+
exceptionCoverage = Math.min(distance, exceptionCoverage);
3031
}
31-
return exceptionCoverage / arrayAccessInfo.size();
32+
return exceptionCoverage;
3233
}
3334

3435
/**

botsing-reproduction/src/main/java/eu/stamp/botsing/fitnessfunction/IntegrationTestingFF.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected double exceptionCoverage(ExecutionResult executionResult) {
6666
do {
6767
crashingClass = resultException.getStackTrace()[++frame].getClassName();
6868
}
69-
while (frame < resultException.getStackTrace().length && (crashingClass.startsWith("java") || crashingClass.startsWith("javax")));
69+
while (frame < resultException.getStackTrace().length && (crashingClass.startsWith("java.") || crashingClass.startsWith("javax.")));
7070
if (frame == resultException.getStackTrace().length) {
7171
continue;
7272
}

botsing-reproduction/src/test/java/eu/stamp/botsing/fitnessfunction/ITFFForArrayIndexTest.java renamed to botsing-reproduction/src/test/java/eu/stamp/botsing/fitnessfunction/ITFFForIndexedAccessTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import static org.mockito.Mockito.mock;
2121

2222
@RunWith(Parameterized.class)
23-
public class ITFFForArrayIndexTest extends IntegrationTestingFFTest {
23+
public class ITFFForIndexedAccessTest extends IntegrationTestingFFTest {
2424

25-
@Parameterized.Parameters(name = "index:{0}, arrayLength:{1}, expectedDistance:{2}")
25+
@Parameterized.Parameters(name = "index:{0}, length:{1}, expectedDistance:{2}")
2626
public static Iterable<Object[]> data() {
2727
return Arrays.asList(new Object[][]{
2828
{-1, 1, 0},
@@ -52,8 +52,10 @@ public void testExceptionCoverage_executionResultWithoutTargetCrash() throws Fil
5252
doReturn(exceptionLocators).when(executionResult).getPositionsWhereExceptionsWereThrown();
5353

5454
ExecutionTraceImpl executionTrace = new ExecutionTraceImpl();
55-
executionTrace.arrayIndexAndLength = new HashMap<>();
56-
executionTrace.arrayIndexAndLength.put(0, new int[]{index, arrayLength});
55+
executionTrace.indexAndLengthMap = new HashMap<>();
56+
executionTrace.indexAndLengthMap.put("eu.stamp.ClassB", new HashMap<>());
57+
executionTrace.indexAndLengthMap.get("eu.stamp.ClassB").put("method1", new HashMap<>());
58+
executionTrace.indexAndLengthMap.get("eu.stamp.ClassB").get("method1").put(0, new int[]{index, arrayLength});
5759

5860
doReturn(executionTrace).when(executionResult).getTrace();
5961

@@ -73,7 +75,7 @@ public void testExceptionCoverage_executionResultWithoutTargetCrash() throws Fil
7375
Mockito.doReturn(obj).when(target).readFromFile(anyString());
7476
target.setup("", 2);
7577

76-
ITFFForArrayIndex itffForArrayIndex = new ITFFForArrayIndex(target);
77-
Assert.assertEquals(expectedDistance, itffForArrayIndex.exceptionCoverage(executionResult), 0.00000001);
78+
ITFFForIndexedAccess itffForIndexedAccess = new ITFFForIndexedAccess(target);
79+
Assert.assertEquals(expectedDistance, itffForIndexedAccess.exceptionCoverage(executionResult), 0.00000001);
7880
}
7981
}

docs/pages/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Currently, Botsing using a customized version of the `evoSuite-client`. Hence, t
1212

1313
1. Installing the customized version of EvoSuite-client:
1414
```Bash
15-
mvn install:install-file -Dfile=botsing-reproduction/evosuite-client-botsing-1.0.7.jar -DgroupId=org.evosuite -DartifactId=evosuite-client-botsing -Dversion=1.0.7 -Dpackaging=jar
15+
mvn install:install-file -Dfile=botsing-reproduction/evosuite-client-botsing-1.1.0.jar -DgroupId=org.evosuite -DartifactId=evosuite-client-botsing -Dversion=1.1.0 -Dpackaging=jar
1616
```
1717

1818
2. Build the Botsing project:

0 commit comments

Comments
 (0)