use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class TestStringSearch method testIndexOfC2.
@Test
public void testIndexOfC2() {
String var1value = ":cc]#0l";
StringVariable var1 = new StringVariable("var0", var1value);
IntegerConstant colon_code = new IntegerConstant(58);
IntegerConstant numeral_code = new IntegerConstant(35);
IntegerConstant minus_one = new IntegerConstant(-1);
StringBinaryToIntegerExpression index_of_colon = new StringBinaryToIntegerExpression(var1, Operator.INDEXOFC, colon_code, -1L);
StringBinaryToIntegerExpression index_of_numeral = new StringBinaryToIntegerExpression(var1, Operator.INDEXOFC, numeral_code, -1L);
/*
* Here we are trying to modify the string such that the first '#' comes
* before the first ':', and both are present
*/
IntegerConstraint constr1 = new IntegerConstraint(index_of_colon, Comparator.NE, minus_one);
IntegerConstraint constr2 = new IntegerConstraint(index_of_numeral, Comparator.NE, minus_one);
IntegerConstraint constr3 = new IntegerConstraint(index_of_numeral, Comparator.LT, index_of_colon);
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(constr1);
constraints.add(constr2);
constraints.add(constr3);
EvoSuiteSolver solver = new EvoSuiteSolver();
Map<String, Object> solution = null;
try {
/*
* The constraint is not trivial, as there are search plateaus. So
* it is ok if sometimes it fails (tried 10 times, failed 3).
*/
final int TRIES = 20;
for (int i = 0; i < TRIES; i++) {
solution = solve(solver, constraints);
if (solution != null) {
break;
}
}
assertNotNull(solution);
String result = solution.get("var0").toString();
int colonPos = result.indexOf(':');
int numeralPos = result.indexOf('#');
assertTrue("Colon not found in " + result, colonPos >= 0);
assertTrue("Numeral not found in " + result, numeralPos >= 0);
assertTrue(colonPos > numeralPos);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class ArithmeticVM method IINC.
/**
* Increment i-th local (int) variable by constant (int) value
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc6.html#iinc
*/
@Override
public void IINC(int i, int value) {
IntegerConstant right = ExpressionFactory.buildNewIntegerConstant(value);
IntegerValue left = env.topFrame().localsTable.getBv32Local(i);
int left_concrete_value = ((Long) left.getConcreteValue()).intValue();
int right_concrete_value = value;
if (!left.containsSymbolicVariable()) {
left = ExpressionFactory.buildNewIntegerConstant(left_concrete_value);
}
int con = left_concrete_value + right_concrete_value;
IntegerValue intExpr = ExpressionFactory.add(left, right, (long) con);
env.topFrame().localsTable.setBv32Local(i, intExpr);
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class ArithmeticVM method zeroViolation.
private boolean zeroViolation(IntegerValue value, long valueConcrete) {
IntegerConstant zero = ExpressionFactory.ICONST_0;
IntegerConstraint zeroCheck;
if (valueConcrete == 0)
zeroCheck = ConstraintFactory.eq(value, zero);
else
zeroCheck = ConstraintFactory.neq(value, zero);
if (zeroCheck.getLeftOperand().containsSymbolicVariable() || zeroCheck.getRightOperand().containsSymbolicVariable())
pathConstraint.addSupportingConstraint(zeroCheck);
if (valueConcrete == 0) {
// JVM will throw an exception
return true;
}
return false;
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class CallVM method METHOD_BEGIN_PARAM.
@Override
public void METHOD_BEGIN_PARAM(int nr, int index, long value) {
if (!env.callerFrame().weInvokedInstrumentedCode()) {
IntegerConstant literal_value = ExpressionFactory.buildNewIntegerConstant(value);
env.topFrame().localsTable.setBv64Local(index, literal_value);
}
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class CallVM method CALL_RESULT.
@Override
public void CALL_RESULT(long res, String owner, String name, String desc) {
CALL_RESULT(owner, name, desc);
if (env.topFrame().weInvokedInstrumentedCode()) {
// RETURN already did it
return;
} else {
/**
* We are returning from uninstrumented code. This is the only way
* of storing the uninstrumented return value to the symbolic state.
*/
IntegerConstant value = ExpressionFactory.buildNewIntegerConstant(res);
env.topFrame().operandStack.pushBv64(value);
}
}
Aggregations