Skip to content
Snippets Groups Projects
Commit 8857f653 authored by Ewen Smith's avatar Ewen Smith
Browse files

Removed all false instructions

parent 852620ba
Branches
No related tags found
No related merge requests found
Pipeline #59159 passed
...@@ -118,22 +118,22 @@ public class Fuzzer { ...@@ -118,22 +118,22 @@ public class Fuzzer {
switch (runCount){ switch (runCount){
case 0: case 0:
// Test with stack full // Test with stack full
return generateInput(true, INSTRUCTION_MAX, MAX_STACK_SIZE, false, false, false); return generateInput(true, INSTRUCTION_MAX, MAX_STACK_SIZE, false, false);
case 1: case 1:
// Test with stack full // Test with stack full
return generateInput(true, INSTRUCTION_MAX, MAX_STACK_SIZE - 1, false, false, false); return generateInput(true, INSTRUCTION_MAX, MAX_STACK_SIZE - 1, false, false);
case 3: case 3:
// Run static tests and empty stack // Run static tests and empty stack
return getStaticTests() + generateInput(true, INSTRUCTION_MAX, 0, false, false, false); return getStaticTests() + generateInput(true, INSTRUCTION_MAX, 0, false, false);
case 4: case 4:
// Test with dynamic probability // Test with dynamic probability
return generateInput(true, INSTRUCTION_MAX, 0, true, false, false); return generateInput(true, INSTRUCTION_MAX, 0, true, false);
case 5: case 5:
// Test with long var names // Test with long var names
return generateInput(true, INSTRUCTION_MAX, 0, false, true, false); return generateInput(true, INSTRUCTION_MAX, 0, false, true);
} }
// Run from random stack // Run from random stack
return generateInput(true, INSTRUCTION_MAX, 0, false, false, false); return generateInput(true, INSTRUCTION_MAX, 0, false, false);
} }
...@@ -155,7 +155,7 @@ public class Fuzzer { ...@@ -155,7 +155,7 @@ public class Fuzzer {
boolean stackFull = rand.nextInt(100) < STACK_FULL_PERCENTAGE; boolean stackFull = rand.nextInt(100) < STACK_FULL_PERCENTAGE;
result.append(generateInput(false, result.append(generateInput(false,
INSTRUCTION_MAX, MAX_STACK_SIZE, false, false, false)); INSTRUCTION_MAX, MAX_STACK_SIZE, false, false));
// Increment generated // Increment generated
generated += 1; generated += 1;
} }
...@@ -201,14 +201,14 @@ public class Fuzzer { ...@@ -201,14 +201,14 @@ public class Fuzzer {
* @param numInstructions for the line * @param numInstructions for the line
* @return the concatenated input for the program as a string * @return the concatenated input for the program as a string
*/ */
private static String generateInput(boolean correct, long numInstructions, int stackPreload, boolean dynamicProb, boolean longVarNames, boolean badInstruct){ private static String generateInput(boolean correct, long numInstructions, int stackPreload, boolean dynamicProb, boolean longVarNames){
int stackSize = 0; int stackSize = 0;
int counter = 0; int counter = 0;
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
for ( int i = 0 ; i < stackPreload ; i++ ) { for ( int i = 0 ; i < stackPreload ; i++ ) {
result.append(completeInstruction(true, Instruction.PUSH, false, false)); result.append(completeInstruction(true, Instruction.PUSH, false));
stackSize++; stackSize++;
} }
...@@ -216,7 +216,7 @@ public class Fuzzer { ...@@ -216,7 +216,7 @@ public class Fuzzer {
while (counter < numInstructions) { while (counter < numInstructions) {
Instruction newInstr = Instruction.getRandomInstruction(stackSize, instructionStack, pathwayProb); Instruction newInstr = Instruction.getRandomInstruction(stackSize, instructionStack, pathwayProb);
stackSize = stackSize + newInstr.getStackChange(); stackSize = stackSize + newInstr.getStackChange();
result.append(completeInstruction(true, newInstr, false, false)); result.append(completeInstruction(true, newInstr, false));
if (dynamicProb) { if (dynamicProb) {
incrementStackAndCount(newInstr); incrementStackAndCount(newInstr);
} }
...@@ -227,13 +227,13 @@ public class Fuzzer { ...@@ -227,13 +227,13 @@ public class Fuzzer {
Instruction newInstr; Instruction newInstr;
if (rand.nextInt(100) < LINE_ERROR_PERCENTAGE){ if (rand.nextInt(100) < LINE_ERROR_PERCENTAGE){
newInstr = Instruction.getRandomInstruction(2, instructionStack, pathwayProb); newInstr = Instruction.getRandomInstruction(2, instructionStack, pathwayProb);
result.append(completeInstruction(false, newInstr, longVarNames, badInstruct)); result.append(completeInstruction(false, newInstr, longVarNames));
if (dynamicProb) { if (dynamicProb) {
incrementStackAndCount(newInstr); incrementStackAndCount(newInstr);
} }
} else { } else {
newInstr = Instruction.getRandomInstruction(stackSize, instructionStack, pathwayProb); newInstr = Instruction.getRandomInstruction(stackSize, instructionStack, pathwayProb);
result.append(completeInstruction(true, newInstr, false, false)); result.append(completeInstruction(true, newInstr, false));
if (dynamicProb) { if (dynamicProb) {
incrementStackAndCount(newInstr); incrementStackAndCount(newInstr);
} }
...@@ -256,7 +256,7 @@ public class Fuzzer { ...@@ -256,7 +256,7 @@ public class Fuzzer {
* @param instruction type * @param instruction type
* @return string with parameter * @return string with parameter
*/ */
private static String completeInstruction(boolean correct, Instruction instruction, boolean longVarNames, boolean badInstruct){ private static String completeInstruction(boolean correct, Instruction instruction, boolean longVarNames){
String name = ""; String name = "";
switch (instruction) { switch (instruction) {
...@@ -266,19 +266,15 @@ public class Fuzzer { ...@@ -266,19 +266,15 @@ public class Fuzzer {
name = " " + ((Integer) randomRange(VAR_MIN, VAR_MAX)).toString(); name = " " + ((Integer) randomRange(VAR_MIN, VAR_MAX)).toString();
} else { } else {
// If incorrect, increase the range to outside +- int31_t // If incorrect, increase the range to outside +- int31_t
if (!badInstruct) {
name = " " + ((Long) (randomRange(-1, 1) * ((long) VAR_MAX + (long) randomRange(0, VAR_MAX)))).toString(); name = " " + ((Long) (randomRange(-1, 1) * ((long) VAR_MAX + (long) randomRange(0, VAR_MAX)))).toString();
} }
}
break; break;
case LOAD: case LOAD:
case REM: case REM:
// If not correct, make up a name not in the list // If not correct, make up a name not in the list
if (!correct){ if (!correct){
if (!badInstruct) {
name = generateName(longVarNames); name = generateName(longVarNames);
} }
}
// If no variables, return empty string // If no variables, return empty string
else if (vars.size() == 0){ else if (vars.size() == 0){
return ""; return "";
...@@ -299,10 +295,8 @@ public class Fuzzer { ...@@ -299,10 +295,8 @@ public class Fuzzer {
} }
// Otherwise get name from exiting, or no name // Otherwise get name from exiting, or no name
else { else {
if (!badInstruct) {
name = vars.get(randomRange(0, vars.size() - 1)); name = vars.get(randomRange(0, vars.size() - 1));
} }
}
name = " " + name; name = " " + name;
...@@ -311,10 +305,8 @@ public class Fuzzer { ...@@ -311,10 +305,8 @@ public class Fuzzer {
if (correct){ if (correct){
name = " " + generateName(false) + ".txt"; name = " " + generateName(false) + ".txt";
} else { } else {
if (!badInstruct) {
name = " " + generateName(longVarNames) + ".txt"; name = " " + generateName(longVarNames) + ".txt";
} }
}
break; break;
case PLUS: case PLUS:
case SUB: case SUB:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment