diff options
author | Feideus <erwan.ulrich@gmail.com> | 2018-07-25 18:12:19 +0200 |
---|---|---|
committer | Feideus <erwan.ulrich@gmail.com> | 2018-07-25 18:12:19 +0200 |
commit | b2ca48cd5b6ee4f17162ff9cabdb75d7c0133997 (patch) | |
tree | 4503b19f7186ef48fa075341db353c580d52f14b /src | |
parent | 967161015a98108369b981585d8cacabbc73b181 (diff) | |
download | schemafuzz-b2ca48cd5b6ee4f17162ff9cabdb75d7c0133997.tar.gz schemafuzz-b2ca48cd5b6ee4f17162ff9cabdb75d7c0133997.tar.bz2 schemafuzz-b2ca48cd5b6ee4f17162ff9cabdb75d7c0133997.zip |
Marking working but not as expected
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/schemaspy/DBFuzzer.java | 104 | ||||
-rw-r--r-- | src/main/java/org/schemaspy/model/GenericTreeNode.java | 16 | ||||
-rw-r--r-- | src/main/java/org/schemaspy/model/ReportVector.java | 10 | ||||
-rw-r--r-- | src/main/java/org/schemaspy/model/Scorer.java | 23 | ||||
-rw-r--r-- | src/test/java/org/schemaspy/model/GenericTreeNodeTest.java | 2 |
5 files changed, 86 insertions, 69 deletions
diff --git a/src/main/java/org/schemaspy/DBFuzzer.java b/src/main/java/org/schemaspy/DBFuzzer.java index fb898da..0218889 100644 --- a/src/main/java/org/schemaspy/DBFuzzer.java +++ b/src/main/java/org/schemaspy/DBFuzzer.java @@ -35,7 +35,7 @@ public class DBFuzzer public boolean processFirstMutation(GenericTreeNode rootMutation) { boolean returnStatus=true; - int nbUpdates; + int nbUpdates = 0; try { if(rootMutation.getChosenChange() != null) @@ -57,21 +57,36 @@ public class DBFuzzer //Evaluation - try - { - double mark; - Process evaluatorProcess = new ProcessBuilder("/bin/bash", "./aLittleBitLessDumbEvaluator.sh").start(); - mark = Double.parseDouble(getEvaluatorResponse(evaluatorProcess)); - rootMutation.setInterest_mark(mark); - rootMutation.setWeight(mark); - rootMutation.propagateWeight(); - System.out.println("marking : "+mark); - System.out.println("Weight : "+rootMutation.getWeight()); - } - catch(Exception e) + if(nbUpdates != 0) { - e.printStackTrace(); - returnStatus = false; + try { + // the evaluator sets a mark for representing how interesting the mutation was + //Process tmpProcess = new ProcessBuilder("/bin/bash", "./emulated_program.sh").start(); // this should go soon now. + //mark = Integer.parseInt(getEvaluatorResponse(tmpProcess)); + //currentMutation.setInterest_mark(mark); + //currentMutation.setWeight(mark); + //currentMutation.propagateWeight(); //update parents weight according to this node new weight + + int mark = 0; + + LOGGER.info("Target is : " + analyzer.getCommandLineArguments().getTarget()); + Process evaluatorProcess = new ProcessBuilder("/bin/bash", "./stackTraceCParser.sh", analyzer.getCommandLineArguments().getTarget(), Integer.toString(rootMutation.getId())).start(); + evaluatorProcess.waitFor(); + ReportVector mutationReport = new ReportVector(rootMutation); + mutationReport.parseFile("errorReports/parsedStackTrace_" + rootMutation.getId()); + rootMutation.setReportVector(mutationReport); + mark = new Scorer().score(rootMutation, mutationTree); + rootMutation.setInterest_mark(mark); + rootMutation.setWeight(mark); + rootMutation.propagateWeight(); + System.out.println("marking : " + mark); + System.out.println("Weight : " + rootMutation.getWeight()); + } + catch (Exception e) + { + e.printStackTrace(); + returnStatus = false; + } } return returnStatus; @@ -82,7 +97,10 @@ public class DBFuzzer boolean returnStatus = true; int TreeDepth = 0; int maxDepth = Integer.parseInt(analyzer.getCommandLineArguments().getMaxDepth()); - double mark = 0.0; + int mark = 0; + int nbUpdates = 0; + + //adding CASCADE to all foreign key tableColumns. settingTemporaryCascade(false); // need to drop and recreate database @@ -138,7 +156,7 @@ public class DBFuzzer { if(currentMutation.getChosenChange() != null) { - int nbUpdates = currentMutation.inject(analyzer.getSqlService(),analyzer.getDb(),mutationTree,false); + nbUpdates = currentMutation.inject(analyzer.getSqlService(),analyzer.getDb(),mutationTree,false); if(nbUpdates > 0) { LOGGER.info("GenericTreeNode was sucessfull"); @@ -180,33 +198,35 @@ public class DBFuzzer returnStatus = false; } - //Evalutation - try - { - // the evaluator sets a mark for representing how interesting the mutation was - Process tmpProcess = new ProcessBuilder("/bin/bash", "./emulated_program.sh").start(); // this should go soon now. - mark = Double.parseDouble(getEvaluatorResponse(tmpProcess)); - currentMutation.setInterest_mark(mark); - currentMutation.setWeight(mark); - currentMutation.propagateWeight(); //update parents weight according to this node new weight - System.out.println("marking : "+mark); - System.out.println("Weight : "+currentMutation.getWeight()); - - LOGGER.info("Target is : "+analyzer.getCommandLineArguments().getTarget()); - Process evaluatorProcess = new ProcessBuilder("/bin/bash", "./stackTraceCParser.sh",analyzer.getCommandLineArguments().getTarget(),Integer.toString(currentMutation.getId())).start(); - evaluatorProcess.waitFor(); - ReportVector mutationReport = new ReportVector(currentMutation); - mutationReport.parseFile("errorReports/parsedStackTrace_"+currentMutation.getId()); - currentMutation.setReportVector(mutationReport); - currentMutation.setInterest_mark(new Scorer().score(currentMutation,mutationTree)); - LOGGER.info(mutationReport.toString()); - } - catch(Exception e) + //Evaluation\ + if(nbUpdates != 0) { - e.printStackTrace(); - returnStatus = false; + try { + // the evaluator sets a mark for representing how interesting the mutation was + //Process tmpProcess = new ProcessBuilder("/bin/bash", "./emulated_program.sh").start(); // this should go soon now. + //mark = Integer.parseInt(getEvaluatorResponse(tmpProcess)); + //currentMutation.setInterest_mark(mark); + //currentMutation.setWeight(mark); + //currentMutation.propagateWeight(); //update parents weight according to this node new weight + + LOGGER.info("Target is : " + analyzer.getCommandLineArguments().getTarget()); + Process evaluatorProcess = new ProcessBuilder("/bin/bash", "./stackTraceCParser.sh", analyzer.getCommandLineArguments().getTarget(), Integer.toString(currentMutation.getId())).start(); + evaluatorProcess.waitFor(); + ReportVector mutationReport = new ReportVector(currentMutation); + mutationReport.parseFile("errorReports/parsedStackTrace_" + currentMutation.getId()); + currentMutation.setReportVector(mutationReport); + mark = new Scorer().score(currentMutation, mutationTree); + currentMutation.setInterest_mark(mark); + currentMutation.setWeight(mark); + currentMutation.propagateWeight(); + System.out.println("marking : " + mark); + System.out.println("Weight : " + currentMutation.getWeight()); + } catch (Exception e) { + e.printStackTrace(); + returnStatus = false; + } + TreeDepth = mutationTree.checkMaxDepth(mutationTree.getRoot()); } - TreeDepth = mutationTree.checkMaxDepth(mutationTree.getRoot()); } removeTemporaryCascade(); diff --git a/src/main/java/org/schemaspy/model/GenericTreeNode.java b/src/main/java/org/schemaspy/model/GenericTreeNode.java index 2d1a81c..7d3b2ba 100644 --- a/src/main/java/org/schemaspy/model/GenericTreeNode.java +++ b/src/main/java/org/schemaspy/model/GenericTreeNode.java @@ -12,8 +12,8 @@ public class GenericTreeNode { private final Integer id; - private double interest_mark; - private double weight; + private int interest_mark; + private int weight; private Integer subTreeWeight; private int depth; private Row initial_state_row; @@ -33,7 +33,7 @@ public class GenericTreeNode { //this.cascadingFK = false; this.subTreeWeight = 0; this.parent = null; - this.weight = 1.0; + this.weight = 1; this.depth = 0; this.id = id; this.isFirstApperance = true; @@ -46,7 +46,7 @@ public class GenericTreeNode { //this.cascadingFK = false; this.parent = parentMutation; this.subTreeWeight = 0; - this.weight = 1.0; + this.weight = 1; this.id = id; initDepth(); this.isFirstApperance = isFirstApperance; @@ -80,7 +80,7 @@ public class GenericTreeNode { this.potential_changes = potCh; } - public double getWeight() { + public int getWeight() { return this.weight; } @@ -118,7 +118,7 @@ public class GenericTreeNode { this.subTreeWeight = tmp; } - public void setWeight(double weight) { + public void setWeight(int weight) { this.weight = weight; } @@ -172,11 +172,11 @@ public class GenericTreeNode { return initial_state_row; } - public double getInterest_mark() { + public int getInterest_mark() { return this.interest_mark; } - public void setInterest_mark(double mark) { + public void setInterest_mark(int mark) { this.interest_mark = mark; } diff --git a/src/main/java/org/schemaspy/model/ReportVector.java b/src/main/java/org/schemaspy/model/ReportVector.java index c6186a1..f2e0aef 100644 --- a/src/main/java/org/schemaspy/model/ReportVector.java +++ b/src/main/java/org/schemaspy/model/ReportVector.java @@ -9,7 +9,7 @@ import java.util.Random; public class ReportVector { private ArrayList<StackTraceLine> stackTrace; - private int stackTraceHash; + private double stackTraceHash; private int codeCoverage; //unused right now GenericTreeNode parentMutation; @@ -19,9 +19,9 @@ public class ReportVector { stackTrace = new ArrayList<StackTraceLine>(); } - public int getStackTraceHash() { return stackTraceHash; } + public double getStackTraceHash() { return stackTraceHash; } - public void setStackTraceHash(int stackTraceHash) { this.stackTraceHash = stackTraceHash; } + public void setStackTraceHash(double stackTraceHash) { this.stackTraceHash = stackTraceHash; } public ArrayList<StackTraceLine> getStackTrace() { return stackTrace; @@ -145,9 +145,9 @@ public class ReportVector { return true; } - public int hashStackTrace(GenericTree mutationTree,GenericTreeNode currentNode) + public double hashStackTrace(GenericTree mutationTree,GenericTreeNode currentNode) { Random rand = new Random(); - return rand.nextInt(); + return rand.nextDouble(); } } diff --git a/src/main/java/org/schemaspy/model/Scorer.java b/src/main/java/org/schemaspy/model/Scorer.java index 907589e..95edea4 100644 --- a/src/main/java/org/schemaspy/model/Scorer.java +++ b/src/main/java/org/schemaspy/model/Scorer.java @@ -52,9 +52,9 @@ public class Scorer { return hash; } - public double score (GenericTreeNode gtn,GenericTree mutationTree) + public int score (GenericTreeNode gtn,GenericTree mutationTree) { - flushContext(); + flushContext(mutationTree); initContext(gtn,mutationTree); Scorer sc = new Scorer(); //Lets create the centroids or 'average' locations of center for our points @@ -70,9 +70,8 @@ public class Scorer { sc.solve(); //Now lets predict our test array - //sc.closestClusterIndex(euclideanDistances); // not used right now cause we need ALL the distances. - return computeScore(); + return computeScore(sc.euclideanDistances); } @@ -110,7 +109,7 @@ public class Scorer { //System.out.println( Arrays.deepToString(this.clusters.values().toArray()) ); iterations += 1; } - + euclideanDistances = euclideanDistance(predict,centroids); } //Lets assign 'labels' or 'outputs' to each of our 'clusters' or grouped set of points @@ -146,8 +145,6 @@ public class Scorer { } } - System.out.println("hash"+hash); - for(int i=0;i<hash.size();i++){ //Lets create a matrix of each groups points to index them by column easier RealMatrix mat = MatrixUtils.createRealMatrix(hash.get(i).toArray(new double[][]{})); @@ -245,7 +242,6 @@ public class Scorer { //Use the distance to each data point(or row) as key with the 'default' option as value euclideanDistances.put( distance , i/*cluster number*/ ); } - System.out.println(euclideanDistances); //Now lets sort the map's keys into a set SortedSet<Double> keys = new TreeSet<Double>(euclideanDistances.keySet()); List<Integer> neighbors = new ArrayList<Integer>(); @@ -253,14 +249,14 @@ public class Scorer { return euclideanDistances;//Return cluster index of shortest distance } - private double computeScore() + private int computeScore(HashMap<Double, Integer> euclideanDistances) { - double res = 0; + Double res = 0.0; for(Double distance : euclideanDistances.keySet()) { res = res + distance; } - return res; + return res.intValue(); } private void initContext(GenericTreeNode gtn,GenericTree mutationTree) @@ -272,16 +268,17 @@ public class Scorer { predict = tmp; for(GenericTreeNode gtnLoop : mutationTree.toArray()) { + double[] data = {gtnLoop.getReportVector().getStackTraceHash(),0,0}; input[i] = data; i++; } } - private void flushContext() + private void flushContext(GenericTree mutationTree) { predict = null; - input = null; + input = new double[mutationTree.toArray().size()][]; clusters = new HashMap(); } diff --git a/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java b/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java index 67c65bf..4b665cb 100644 --- a/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java +++ b/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java @@ -94,7 +94,7 @@ public class GenericTreeNodeTest extends AbstractTestExecutionListener { tmpMutation1.setWeight(rand.nextInt(Integer.MAX_VALUE)); tmpMutation2.setWeight(rand.nextInt(Integer.MAX_VALUE)); - tmpMutation3.setWeight(Integer.MAX_VALUE); + tmpMutation3.setWeight(rand.nextInt(Integer.MAX_VALUE)); tmpMutation1.addChild(tmpMutation2); tmpMutation1.addChild(tmpMutation3); |