Skip to content

Commit 070e144

Browse files
committed
last version
1 parent f74cc5c commit 070e144

File tree

10 files changed

+87
-68313
lines changed

10 files changed

+87
-68313
lines changed

src/main/java/edu/uniandes/tsdl/mutapk/MutAPK.java

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ public static void runMutAPK(String[] args) throws NumberFormatException, FileNo
160160

161161
// Check Dead Code Methods
162162

163-
// for(Entry<String, HashMap<String, CallGraphNode>> entry : deadCode.entrySet()) {
164-
// System.out.println(entry.getKey());
165-
// for(Entry<String, CallGraphNode> entryy : entry.getValue().entrySet()) {
166-
// System.out.println(" "+entryy.getKey());
167-
// }
168-
// }
163+
// for(Entry<String, HashMap<String, CallGraphNode>> entry : deadCode.entrySet()) {
164+
// System.out.println(entry.getKey());
165+
// for(Entry<String, CallGraphNode> entryy : entry.getValue().entrySet()) {
166+
// System.out.println(" "+entryy.getKey());
167+
// }
168+
// }
169169

170170
// Prune ASTs
171171
for(Entry<String, SmaliAST> entry: smaliASTs.entrySet()) {
@@ -208,11 +208,6 @@ public static void runMutAPK(String[] args) throws NumberFormatException, FileNo
208208
System.out.println(list.size() + " | " + mutationType);
209209
}
210210

211-
// Check if the amount of PFLocations is lower than the requested by the user
212-
if(totalMutants < amountMutants) {
213-
throw new MutAPKException("The total of mutants need to be greater than the amount of mutants asked");
214-
}
215-
System.out.println("");
216211

217212
// Build MutationLocation List
218213
List<MutationLocation> mutationLocationList = MutationLocationListBuilder.buildList(locations);
@@ -221,47 +216,49 @@ public static void runMutAPK(String[] args) throws NumberFormatException, FileNo
221216
System.out.println();
222217
System.out.println("--------------------------------------");
223218

224-
// Select Selector
225-
switch (selectionStrategy) {
226-
case AMOUNT_MUTANTS_SS:
227-
SelectorAmountMutantsMethod selectorAmountMutantsMethod = new SelectorAmountMutantsMethod();
228-
SelectorAmountMutants selectorAmountMutants = new SelectorAmountMutants(false, false, totalMutants,
229-
amountMutants);
230-
mutationLocationList = selectorAmountMutantsMethod.mutantSelector(locations, selectorAmountMutants);
231-
break;
232-
case REPRESENTATIVE_SUBSET_SS:
233-
SelectorConfidenceInterval selectorConfidenceInterval = new SelectorConfidenceInterval(true, false,
234-
totalMutants, isRSPerOPerator, confidenceLevel, marginError);
235-
SelectorConfidenceIntervalMethod CIMS = new SelectorConfidenceIntervalMethod();
236-
mutationLocationList = CIMS.mutantSelector(locations, selectorConfidenceInterval);
237-
break;
238-
default:
239-
break;
240-
}
241-
System.out.println("");
219+
if(ignoreDeadCode) {
220+
// Select Selector
221+
switch (selectionStrategy) {
222+
case AMOUNT_MUTANTS_SS:
223+
SelectorAmountMutantsMethod selectorAmountMutantsMethod = new SelectorAmountMutantsMethod();
224+
SelectorAmountMutants selectorAmountMutants = new SelectorAmountMutants(false, false, totalMutants,
225+
amountMutants);
226+
mutationLocationList = selectorAmountMutantsMethod.mutantSelector(locations, selectorAmountMutants);
227+
break;
228+
case REPRESENTATIVE_SUBSET_SS:
229+
SelectorConfidenceInterval selectorConfidenceInterval = new SelectorConfidenceInterval(true, false,
230+
totalMutants, isRSPerOPerator, confidenceLevel, marginError);
231+
SelectorConfidenceIntervalMethod CIMS = new SelectorConfidenceIntervalMethod();
232+
mutationLocationList = CIMS.mutantSelector(locations, selectorConfidenceInterval);
233+
break;
234+
default:
235+
break;
236+
}
237+
System.out.println("");
242238

243-
System.out.println("## Mutation Process Log");
244-
System.out.println();
245-
System.out.println("```sh");
239+
System.out.println("## Mutation Process Log");
240+
System.out.println();
241+
System.out.println("```sh");
246242

247-
// Execute mutation phase
248-
MutationsProcessor mProcessor = new MutationsProcessor("temp", appName, mutantsFolder);
243+
// Execute mutation phase
244+
MutationsProcessor mProcessor = new MutationsProcessor("temp", appName, mutantsFolder);
249245

250-
// Create de apkhash for the base folder
251-
File manifest = new File(apkAbsolutePath + File.separator + "AndroidManifest.xml");
252-
File smali = new File(apkAbsolutePath + File.separator + "smali");
253-
File resource = new File(apkAbsolutePath + File.separator + "res");
246+
// Create de apkhash for the base folder
247+
File manifest = new File(apkAbsolutePath + File.separator + "AndroidManifest.xml");
248+
File smali = new File(apkAbsolutePath + File.separator + "smali");
249+
File resource = new File(apkAbsolutePath + File.separator + "res");
254250

255251

256-
// Create ApkHashSeparator
257-
ApkHashSeparator apkHashSeparator = mProcessor.generateApkHashSeparator(manifest, smali, resource, 0);
258-
// Add the base apkHashSeparator
259-
ApkHashOrder.getInstance().setApkHashSeparator(apkHashSeparator);
252+
// Create ApkHashSeparator
253+
ApkHashSeparator apkHashSeparator = mProcessor.generateApkHashSeparator(manifest, smali, resource, 0);
254+
// Add the base apkHashSeparator
255+
ApkHashOrder.getInstance().setApkHashSeparator(apkHashSeparator);
260256

261-
if (multithread) {
262-
mProcessor.processMultithreaded(mutationLocationList, extraPath, apkName);
263-
} else {
264-
mProcessor.process(mutationLocationList, extraPath, apkName);
257+
if (multithread) {
258+
mProcessor.processMultithreaded(mutationLocationList, extraPath, apkName);
259+
} else {
260+
mProcessor.process(mutationLocationList, extraPath, apkName);
261+
}
265262
}
266263

267264
}

src/main/java/edu/uniandes/tsdl/mutapk/processors/MutationsProcessor.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private String setupMutantFolder(int mutantIndex) throws IOException {
4848

4949
}
5050

51-
public void process(List<MutationLocation> locations, String extraPath, String apkName)
51+
public void process(List<MutationLocation> locations, String extraPath, String apkName)
5252
throws IOException, ParserConfigurationException, SAXException, InterruptedException {
5353
MutationOperatorFactory factory = MutationOperatorFactory.getInstance();
5454
MutationOperator operator = null;
@@ -81,14 +81,23 @@ public void process(List<MutationLocation> locations, String extraPath, String a
8181
newMutationPath = mutationLocation.getFilePath().replace(appFolder, mutantFolder);
8282
// System.out.println(newMutationPath);
8383
mutationLocation.setFilePath(newMutationPath);
84-
operator.performMutation(mutationLocation, writer, mutantIndex);
85-
Long mutationEnd = System.currentTimeMillis();
86-
Long mutationTime = mutationEnd - mutationIni;
87-
88-
// Verify id the mutant is a duplicate
89-
verifyDuplicateMutants(extraPath, apkName, mutantIndex, mutantFolder, newMutationPath, wwriter,
90-
mutationLocation, mutationEnd, mutationTime);
91-
mutantIndex++;
84+
try {
85+
operator.performMutation(mutationLocation, writer, mutantIndex);
86+
Long mutationEnd = System.currentTimeMillis();
87+
Long mutationTime = mutationEnd - mutationIni;
88+
89+
// Verify id the mutant is a duplicate
90+
verifyDuplicateMutants(extraPath, apkName, mutantIndex, mutantFolder, newMutationPath, wwriter,
91+
mutationLocation, mutationEnd, mutationTime);
92+
mutantIndex++;
93+
} catch (Exception e) {
94+
wwriter.write(mutantIndex + ";" + mutationLocation.getType().getId() + ";0;0;0;0;1;0;-1");
95+
wwriter.newLine();
96+
wwriter.flush();
97+
98+
System.out.println(e.getMessage());
99+
}
100+
92101
}
93102
System.out.println("------------------------------------------------------------------------------------");
94103
System.out.println("The maximum id is : " + ApkHashOrder.getInstance().getId());
@@ -202,12 +211,21 @@ public String call() throws NullPointerException, Exception {
202211
String newMutationPath = mutationLocation.getFilePath().replace(appFolder, mutantFolder);
203212
mutationLocation.setFilePath(newMutationPath);
204213

205-
operator.performMutation(mutationLocation, writer, currentMutationIndex);
206-
Long mutationEnd = System.currentTimeMillis();
207-
Long mutationTime = mutationEnd - mutationIni;
208-
209-
// Perform mutation
210-
verifyDuplicateMutants(extraPath, apkName, currentMutationIndex, mutantFolder, newMutationPath, wwriter, mutationLocation, mutationEnd, mutationTime);
214+
try {
215+
operator.performMutation(mutationLocation, writer, currentMutationIndex);
216+
Long mutationEnd = System.currentTimeMillis();
217+
Long mutationTime = mutationEnd - mutationIni;
218+
219+
// Verify id the mutant is a duplicate
220+
verifyDuplicateMutants(extraPath, apkName, currentMutationIndex, mutantFolder, newMutationPath, wwriter,
221+
mutationLocation, mutationEnd, mutationTime);
222+
} catch (InterruptedException | IOException | ParserConfigurationException | SAXException e) {
223+
wwriter.write(currentMutationIndex + ";" + mutationLocation.getType().getId() + ";0;0;0;0;1;0;-1");
224+
wwriter.newLine();
225+
wwriter.flush();
226+
227+
System.out.println(e.getMessage());
228+
}
211229

212230
return "";
213231
}

src/main/java/edu/uniandes/tsdl/mutapk/selector/InterfaceSelector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import java.util.HashMap;
44
import java.util.List;
55

6+
import edu.uniandes.tsdl.mutapk.exception.MutAPKException;
67
import edu.uniandes.tsdl.mutapk.model.MutationType;
78
import edu.uniandes.tsdl.mutapk.model.location.MutationLocation;
89

910
public interface InterfaceSelector {
1011

1112
public List<MutationLocation> mutantSelector(HashMap<MutationType, List<MutationLocation>> locations,
12-
SelectorType selectorType);
13+
SelectorType selectorType) throws MutAPKException;
1314

1415
}

src/main/java/edu/uniandes/tsdl/mutapk/selector/SelectorAmountMutantsMethod.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@
55
import java.util.List;
66

77
import edu.uniandes.tsdl.mutapk.detectors.MutationLocationListBuilder;
8+
import edu.uniandes.tsdl.mutapk.exception.MutAPKException;
89
import edu.uniandes.tsdl.mutapk.model.MutationType;
910
import edu.uniandes.tsdl.mutapk.model.location.MutationLocation;
1011

1112
public class SelectorAmountMutantsMethod implements InterfaceSelector{
1213

1314
public SelectorAmountMutantsMethod() {}
1415

15-
public List<MutationLocation> mutantSelector(HashMap<MutationType, List<MutationLocation>> locations, SelectorType selectorType) {
16+
public List<MutationLocation> mutantSelector(HashMap<MutationType, List<MutationLocation>> locations, SelectorType selectorType) throws MutAPKException {
1617

1718
HashMap<MutationType, List<MutationLocation>> newLocations = new HashMap<MutationType, List<MutationLocation>>();
1819
HashMap<MutationType, List<MutationLocation>> tempLocations = locations;
1920
SelectorAmountMutants selectorAmountMutants = (SelectorAmountMutants) selectorType;
2021
int newAmountMutants = selectorAmountMutants.getAmountMutants();
22+
List<MutationLocation> mutationLocationList = MutationLocationListBuilder.buildList(tempLocations);
23+
24+
// Check if the amount of PFLocations is lower than the requested by the user
25+
if(mutationLocationList.size() < newAmountMutants) {
26+
throw new MutAPKException("The total of mutants need to be greater than the amount of mutants asked");
27+
}
28+
System.out.println("");
2129

2230
for (MutationType key : tempLocations.keySet()) {
2331
if (tempLocations.get(key).size() > 0) {
@@ -30,7 +38,6 @@ public List<MutationLocation> mutantSelector(HashMap<MutationType, List<Mutation
3038
newAmountMutants--;
3139
}
3240
}
33-
List<MutationLocation> mutationLocationList = MutationLocationListBuilder.buildList(tempLocations);
3441
List<MutationLocation> newMutationLocationList = MutationLocationListBuilder.buildList(newLocations);
3542

3643
for (int i = 0; i < newAmountMutants; i++) {

test/result.md

-5.48 KB
Binary file not shown.

0 commit comments

Comments
 (0)