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

Created flag to turn on/off dynamic probabilities

parent 809e872b
Branches
No related tags found
No related merge requests found
Pipeline #58365 passed
......@@ -113,16 +113,19 @@ public class Fuzzer {
switch (runCount){
case 0:
// Test with stack full
return generateInput(true, INSTRUCTION_MAX, MAX_STACK_SIZE);
return generateInput(true, INSTRUCTION_MAX, MAX_STACK_SIZE, false);
case 1:
// Test with stack full
return generateInput(true, INSTRUCTION_MAX, MAX_STACK_SIZE - 1);
return generateInput(true, INSTRUCTION_MAX, MAX_STACK_SIZE - 1, false);
case 3:
// Run static tests and empty stack
return getStaticTests() + generateInput(true, INSTRUCTION_MAX, 0);
return getStaticTests() + generateInput(true, INSTRUCTION_MAX, 0, false);
case 4:
// Test with dynamic probability
return generateInput(true, INSTRUCTION_MAX, 0, true);
}
// Run from random stack
return generateInput(true, INSTRUCTION_MAX, 0);
return generateInput(true, INSTRUCTION_MAX, 0, false);
}
/*
......@@ -154,7 +157,7 @@ public class Fuzzer {
boolean stackFull = rand.nextInt(100) < STACK_FULL_PERCENTAGE;
result.append(generateInput(false,
INSTRUCTION_MAX, MAX_STACK_SIZE));
INSTRUCTION_MAX, MAX_STACK_SIZE, false));
// Increment generated
generated += 1;
}
......@@ -168,7 +171,7 @@ 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, int stackPreload ){
private static String generateInput(boolean correct, long numInstructions, int stackPreload, boolean dynamicProb){
int stackSize = 0;
int counter = 0;
......@@ -184,7 +187,9 @@ public class Fuzzer {
Instruction newInstr = Instruction.getRandomInstruction(stackSize, addProb);
stackSize = stackSize + newInstr.getStackChange();
result.append(completeInstruction(true, newInstr));
if (dynamicProb) {
addCountProb(newInstr);
}
counter += 1;
}
} else {
......@@ -193,12 +198,16 @@ public class Fuzzer {
if (rand.nextInt(100) < LINE_ERROR_PERCENTAGE){
newInstr = Instruction.getRandomInstruction(2, addProb);
result.append(completeInstruction(false, newInstr));
if (dynamicProb) {
addCountProb(newInstr);
}
} else {
newInstr = Instruction.getRandomInstruction(stackSize, addProb);
result.append(completeInstruction(true, newInstr));
if (dynamicProb) {
addCountProb(newInstr);
}
}
stackSize = stackSize + newInstr.getStackChange();
if (stackSize < 0){
stackSize = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment