diff --git a/fuzzer/Fuzzer.java b/fuzzer/Fuzzer.java
index 37553b4bfb58ac1fddecb50cd4b91211b0db3398..e4f577b85d324a728b5d0721a8d445b70f8584ff 100644
--- a/fuzzer/Fuzzer.java
+++ b/fuzzer/Fuzzer.java
@@ -1,14 +1,16 @@
+import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
-import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Random;
+import java.util.Scanner;
/* a stub for your team's fuzzer */
public class Fuzzer {
+ // Blah - Test 3
private static final String OUTPUT_FILE = "fuzz.txt";
@@ -22,7 +24,7 @@ public class Fuzzer {
private static final int NUMBER_TO_GENERATE = 10;
// Instruction number range for each input
private static final int INSTRUCTION_MIN = 0;
- private static final int INSTRUCTION_MAX = 100;
+ private static final int INSTRUCTION_MAX = 1000;
// Maximum variable name length
private static final int VAR_NAME_LENGTH_MAX = 100;
private static final int VAR_ASCII_MIN = 33;
@@ -47,6 +49,7 @@ public class Fuzzer {
System.out.println(Instruction.getBNF());
FileOutputStream out = null;
PrintWriter pw = null;
+ int runCount = getRun();
try {
out = new FileOutputStream(OUTPUT_FILE);
@@ -55,8 +58,8 @@ public class Fuzzer {
/* We just print one instruction.
Hint: you might want to make use of the instruction
grammar which is effectively encoded in Instruction.java */
- pw.print(getStaticTests());
- pw.println(generateMultipleInputs());
+ // pw.print(getStaticTests());
+ pw.println(generateRunInputs(runCount));
}catch (Exception e){
e.printStackTrace(System.err);
@@ -69,8 +72,51 @@ public class Fuzzer {
out.close();
}
}
+ writeRun(runCount);
+ }
+
+ private static int getRun(){
+ int runCount = 0;
+ try {
+ Scanner input = new Scanner(new File("runCount.txt"));
+ runCount = input.nextInt() + 1;
+ } catch (Exception e){
+ // Carry on
+ }
+ return runCount;
+ }
+ private static void writeRun(int runCount) throws IOException {
+ FileOutputStream out = null;
+ PrintWriter pw = null;
+
+ try {
+ out = new FileOutputStream("runCount.txt");
+ pw = new PrintWriter(out);
+
+ pw.print(runCount);
+
+ }catch (Exception e){
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }finally{
+ if (pw != null){
+ pw.flush();
+ }
+ if (out != null){
+ out.close();
+ }
+ }
+ }
+ private static String generateRunInputs(int runCount){
+ switch (runCount){
+ case 0:
+ return generateInput(false, INSTRUCTION_MAX, true);
+ case 1:
+ return generateInput(true, INSTRUCTION_MAX, true);
+ }
+ return generateInput(true, INSTRUCTION_MAX, false);
}
/*
@@ -99,8 +145,10 @@ public class Fuzzer {
// Loop to create list of inputs
while (generated < NUMBER_TO_GENERATE) {
// Determine if the line will be correct or not
+ boolean stackFull = rand.nextInt(100) < STACK_FULL_PERCENTAGE;
+
result.append(generateInput(false,
- INSTRUCTION_MAX));
+ INSTRUCTION_MAX, stackFull));
// Increment generated
generated += 1;
}
@@ -114,13 +162,13 @@ public class Fuzzer {
* @param numInstructions for the line
* @return the concatenated input for the program as a string
*/
- private static String generateInput(boolean correct, long numInstructions){
+ private static String generateInput(boolean correct, long numInstructions, boolean stackFull ){
int stackSize = 0;
int counter = 0;
StringBuilder result = new StringBuilder();
- if (rand.nextInt(100) < STACK_FULL_PERCENTAGE) {
+ if (stackFull) {
for ( int i = 0 ; i < MAX_STACK_SIZE ; i++ ) {
result.append(completeInstruction(true, Instruction.PUSH));
stackSize++;
@@ -196,9 +244,18 @@ public class Fuzzer {
}
break;
case STORE:
- // Make up a name
- name = name + generateName();
- vars.add(name);
+ // If not correct, make up a name not in the list
+ if (correct || vars.size() == 0){
+ // Make up a name
+ name = generateName();
+ vars.add(name);
+ }
+ // If no variables, return empty string
+ else {
+ name = vars.get(randomRange(0,vars.size()-1));
+ }
+
+
name = " " + name;
break;
case SAVE:
diff --git a/runCount.txt b/runCount.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391