List of usage examples for org.objectweb.asm Opcodes IFGT
int IFGT
To view the source code for org.objectweb.asm Opcodes IFGT.
Click Source Link
From source file:org.evosuite.instrumentation.testability.StringTransformation.java
License:Open Source License
/** * <p>/*from w ww . j a v a 2 s .c o m*/ * transformMethod * </p> * * @param mn * a {@link org.objectweb.asm.tree.MethodNode} object. * @return a boolean. */ public boolean transformMethod(MethodNode mn) { boolean changed = transformStrings(mn); if (changed) { try { mn.maxStack++; Analyzer a = new Analyzer(new StringBooleanInterpreter()); a.analyze(cn.name, mn); Frame[] frames = a.getFrames(); AbstractInsnNode node = mn.instructions.getFirst(); boolean done = false; while (!done) { if (node == mn.instructions.getLast()) done = true; AbstractInsnNode next = node.getNext(); int index = mn.instructions.indexOf(node); if (index >= frames.length) break; Frame current = frames[index]; if (current == null) break; int size = current.getStackSize(); if (node.getOpcode() == Opcodes.IFNE) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious())) { logger.info("IFNE -> IFGT"); branch.setOpcode(Opcodes.IFGT); } } else if (node.getOpcode() == Opcodes.IFEQ) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious())) { logger.info("IFEQ -> IFLE"); branch.setOpcode(Opcodes.IFLE); } } else if (node.getOpcode() == Opcodes.IF_ICMPEQ) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious().getPrevious())) { if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) { branch.setOpcode(Opcodes.IFLE); mn.instructions.remove(node.getPrevious()); } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) { branch.setOpcode(Opcodes.IFGT); mn.instructions.remove(node.getPrevious()); } } } else if (node.getOpcode() == Opcodes.IF_ICMPNE) { JumpInsnNode branch = (JumpInsnNode) node; if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious().getPrevious())) { if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) { branch.setOpcode(Opcodes.IFGT); mn.instructions.remove(node.getPrevious()); } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) { branch.setOpcode(Opcodes.IFLE); mn.instructions.remove(node.getPrevious()); } } } else if (node.getOpcode() == Opcodes.IRETURN) { if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN || isStringMethod(node.getPrevious())) { logger.info("IFEQ -> IFLE"); MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "intToBoolean", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE }), false); mn.instructions.insertBefore(node, n); } } node = next; } } catch (Exception e) { logger.warn("EXCEPTION DURING STRING TRANSFORMATION: " + e); return changed; } } return changed; }
From source file:org.evosuite.instrumentation.testability.transformer.BooleanDistanceTransformer.java
License:Open Source License
@Override protected AbstractInsnNode transformJumpInsnNode(MethodNode mn, JumpInsnNode jumpNode) { switch (jumpNode.getOpcode()) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: TransformationStatistics.insertPush(jumpNode.getOpcode()); this.booleanTestabilityTransformation.insertPush(jumpNode.getOpcode(), jumpNode, mn.instructions); break;/*from ww w. j av a2 s . c om*/ case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: TransformationStatistics.insertPush(jumpNode.getOpcode()); this.booleanTestabilityTransformation.insertPush2(jumpNode.getOpcode(), jumpNode, mn.instructions); break; case Opcodes.IFNULL: case Opcodes.IFNONNULL: TransformationStatistics.insertPush(jumpNode.getOpcode()); this.booleanTestabilityTransformation.insertPushNull(jumpNode.getOpcode(), jumpNode, mn.instructions); break; case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: TransformationStatistics.insertPush(jumpNode.getOpcode()); this.booleanTestabilityTransformation.insertPushEquals(jumpNode.getOpcode(), jumpNode, mn.instructions); break; default: // GOTO, JSR: Do nothing } return jumpNode; }
From source file:org.evosuite.instrumentation.testability.transformer.BooleanIfTransformer.java
License:Open Source License
@Override protected AbstractInsnNode transformJumpInsnNode(MethodNode mn, JumpInsnNode jumpNode) { if (jumpNode.getOpcode() == Opcodes.IFNE) { if (this.booleanTestabilityTransformation.isBooleanOnStack(mn, jumpNode, 0)) { TransformationStatistics.transformedBooleanComparison(); BooleanTestabilityTransformation.logger.info("Changing IFNE"); jumpNode.setOpcode(Opcodes.IFGT); } else {/*from ww w. j a va2 s. c o m*/ BooleanTestabilityTransformation.logger.info("Not changing IFNE"); int insnPosition = mn.instructions.indexOf(jumpNode); Frame frame = this.booleanTestabilityTransformation.currentFrames[insnPosition]; AbstractInsnNode insn = mn.instructions.get(insnPosition - 1); BooleanTestabilityTransformation.logger.info("Current node: " + mn.instructions.get(insnPosition)); BooleanTestabilityTransformation.logger.info("Previous node: " + insn); if (insn instanceof MethodInsnNode) { MethodInsnNode mi = (MethodInsnNode) insn; if (Type.getReturnType(DescriptorMapping.getInstance().getMethodDesc(mi.owner, mi.name, mi.desc)) == Type.BOOLEAN_TYPE) { BooleanTestabilityTransformation.logger.info("Changing IFNE"); jumpNode.setOpcode(Opcodes.IFGT); } BooleanTestabilityTransformation.logger.info("Method: " + mi.name); } BooleanTestabilityTransformation.logger.info("Stack size: " + frame.getStackSize()); //logger.info("Top of stack: " + frame.getStack(0)); for (int i = 0; i < frame.getStackSize(); i++) { BooleanTestabilityTransformation.logger.info(i + " Stack: " + frame.getStack(i)); } } } else if (jumpNode.getOpcode() == Opcodes.IFEQ) { if (this.booleanTestabilityTransformation.isBooleanOnStack(mn, jumpNode, 0)) { TransformationStatistics.transformedBooleanComparison(); BooleanTestabilityTransformation.logger.info("Changing IFEQ"); jumpNode.setOpcode(Opcodes.IFLE); } else { BooleanTestabilityTransformation.logger.info("Not changing IFEQ"); int insnPosition = mn.instructions.indexOf(jumpNode); Frame frame = this.booleanTestabilityTransformation.currentFrames[insnPosition]; AbstractInsnNode insn = mn.instructions.get(insnPosition - 1); BooleanTestabilityTransformation.logger.info("Previous node: " + insn); if (insn instanceof MethodInsnNode) { MethodInsnNode mi = (MethodInsnNode) insn; BooleanTestabilityTransformation.logger.info("Method: " + mi.name); if (Type.getReturnType(BooleanTestabilityTransformation.getOriginalDesc(mi.owner, mi.name, mi.desc)) == Type.BOOLEAN_TYPE) { BooleanTestabilityTransformation.logger.info("Changing IFEQ"); jumpNode.setOpcode(Opcodes.IFLE); } else { BooleanTestabilityTransformation.logger.info("Return type: " + Type.getReturnType( BooleanTestabilityTransformation.getOriginalDesc(mi.owner, mi.name, mi.desc))); } } BooleanTestabilityTransformation.logger.info("Stack size: " + frame.getStackSize()); for (int i = 0; i < frame.getStackSize(); i++) { BooleanTestabilityTransformation.logger.info(i + " Stack: " + frame.getStack(i)); } } } else if (jumpNode.getOpcode() == Opcodes.IF_ICMPEQ) { if (this.booleanTestabilityTransformation.isBooleanOnStack(mn, jumpNode, 0)) { InsnList convert = new InsnList(); convert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushParameter", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE }))); convert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushParameter", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE }))); convert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "popParameterBooleanFromInt", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] {}))); convert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "popParameterBooleanFromInt", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] {}))); mn.instructions.insertBefore(jumpNode, convert); TransformationStatistics.transformedBooleanComparison(); } } else if (jumpNode.getOpcode() == Opcodes.IF_ICMPNE) { if (this.booleanTestabilityTransformation.isBooleanOnStack(mn, jumpNode, 0)) { InsnList convert = new InsnList(); convert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushParameter", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE }))); convert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushParameter", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE }))); convert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "popParameterBooleanFromInt", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] {}))); convert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "popParameterBooleanFromInt", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] {}))); mn.instructions.insertBefore(jumpNode, convert); TransformationStatistics.transformedBooleanComparison(); } } return jumpNode; }
From source file:org.evosuite.instrumentation.TransformationStatistics.java
License:Open Source License
/** * Insertion of pushDistance/*from w ww .j a v a 2 s. c o m*/ * * @param opcode a int. */ public static void insertPush(int opcode) { switch (opcode) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: insertedPushInt0++; break; case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: insertedPushInt1++; break; case Opcodes.IFNULL: case Opcodes.IFNONNULL: insertedPushIntRef++; break; case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: insertedPushIntNull++; break; default: // GOTO, JSR: Do nothing } }
From source file:org.evosuite.regression.bytecode.RegressionClassDiff.java
License:Open Source License
private static String getBranchFamily(int opcode) { // The default family is the opcode itself // Admittedly we could've use ints/enums for performance, but strings should be interned anyway String family = "" + opcode; switch (opcode) { // copmpare int with zero case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: family = "int_zero"; break;/*from www.j ava2 s . c o m*/ // copmpare int with int case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: family = "int_int"; break; // copmpare reference with reference case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: family = "ref_ref"; break; // compare reference with null case Opcodes.IFNULL: case Opcodes.IFNONNULL: family = "ref_null"; break; } return family; }
From source file:org.evosuite.regression.RegressionClassDiff.java
License:Open Source License
public static String getBranchFamily(int opcode) { // The default family is the opcode itself // Admittedly we could've use ints/enums for performance, but strings should be interned anyway String family = "" + opcode; switch (opcode) { // copmpare int with zero case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: family = "int_zero"; break;/*from www. j ava 2s .c om*/ // copmpare int with int case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: family = "int_int"; break; // copmpare reference with reference case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: family = "ref_ref"; break; // compare reference with null case Opcodes.IFNULL: case Opcodes.IFNONNULL: family = "ref_null"; break; } return family; }
From source file:org.evosuite.testcase.execution.ExecutionTraceImpl.java
License:Open Source License
/** * {@inheritDoc}// ww w . j a v a 2 s. c o m * * Add branch to currently active method call */ @Override public void branchPassed(int branch, int bytecode_id, double true_distance, double false_distance) { assert (true_distance >= 0.0); assert (false_distance >= 0.0); updateTopStackMethodCall(branch, bytecode_id, true_distance, false_distance); // TODO: property should really be called TRACK_GRADIENT_BRANCHES! if (Properties.TRACK_BOOLEAN_BRANCHES) { if ((true_distance != 0 && true_distance != 1) || (false_distance != 0 && false_distance != 1)) gradientBranches.add(branch); } if (traceCoverage) { if (!coveredPredicates.containsKey(branch)) coveredPredicates.put(branch, 1); else coveredPredicates.put(branch, coveredPredicates.get(branch) + 1); if (true_distance == 0.0) { if (!coveredTrue.containsKey(branch)) coveredTrue.put(branch, 1); else coveredTrue.put(branch, coveredTrue.get(branch) + 1); } if (false_distance == 0.0) { if (!coveredFalse.containsKey(branch)) coveredFalse.put(branch, 1); else coveredFalse.put(branch, coveredFalse.get(branch) + 1); } } if (Properties.TRACK_COVERED_GRADIENT_BRANCHES) { if (gradientBranches.contains(branch)) { if ((coveredTrue.containsKey(branch))) gradientBranchesCoveredTrue.add(branch); if ((coveredFalse.containsKey(branch))) gradientBranchesCoveredFalse.add(branch); } } if (Properties.BRANCH_COMPARISON_TYPES) { int opcode = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()) .getBranch(branch).getInstruction().getASMNode().getOpcode(); int previousOpcode = -2; if (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branch) .getInstruction().getASMNode().getPrevious() != null) previousOpcode = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()) .getBranch(branch).getInstruction().getASMNode().getPrevious().getOpcode(); boolean cTrue = coveredTrue.containsKey(branch); boolean cFalse = coveredFalse.containsKey(branch); switch (previousOpcode) { case Opcodes.LCMP: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_lcmp, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_lcmp, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_lcmp, branch); break; case Opcodes.FCMPL: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_fcmpl, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_fcmpl, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_fcmpl, branch); break; case Opcodes.FCMPG: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_fcmpg, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_fcmpg, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_fcmpg, branch); break; case Opcodes.DCMPL: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_dcmpl, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_dcmpl, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_dcmpl, branch); break; case Opcodes.DCMPG: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_dcmpg, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_dcmpg, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_dcmpg, branch); break; } switch (opcode) { // copmpare int with zero case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_IntZero, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_IntZero, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_IntZero, branch); break; // copmpare int with int case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_IntInt, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_IntInt, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_IntInt, branch); break; // copmpare reference with reference case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_RefRef, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_RefRef, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_RefRef, branch); break; // compare reference with null case Opcodes.IFNULL: case Opcodes.IFNONNULL: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_RefNull, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_RefNull, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_RefNull, branch); break; } } if (!trueDistances.containsKey(branch)) trueDistances.put(branch, true_distance); else trueDistances.put(branch, Math.min(trueDistances.get(branch), true_distance)); if (!falseDistances.containsKey(branch)) falseDistances.put(branch, false_distance); else falseDistances.put(branch, Math.min(falseDistances.get(branch), false_distance)); if (!trueDistancesSum.containsKey(branch)) trueDistancesSum.put(branch, true_distance); else trueDistancesSum.put(branch, trueDistancesSum.get(branch) + true_distance); if (!falseDistancesSum.containsKey(branch)) falseDistancesSum.put(branch, false_distance); else falseDistancesSum.put(branch, falseDistancesSum.get(branch) + false_distance); if (!disableContext && (Properties.INSTRUMENT_CONTEXT || Properties.INSTRUMENT_METHOD_CALLS || ArrayUtil.contains(Properties.CRITERION, Criterion.IBRANCH) || ArrayUtil.contains(Properties.CRITERION, Criterion.CBRANCH))) { updateBranchContextMaps(branch, true_distance, false_distance); } // This requires a lot of memory and should not really be used if (Properties.BRANCH_EVAL) { branchesTrace.add(new BranchEval(branch, true_distance, false_distance)); } }
From source file:org.evosuite.testcase.execution.ExecutionTracer.java
License:Open Source License
/** * Called by the instrumented code each time a new branch is taken * //from ww w . jav a 2 s . c o m * @param val * a int. * @param opcode * a int. * @param branch * a int. * @param bytecode_id * a int. */ public static void passedBranch(int val, int opcode, int branch, int bytecode_id) { ExecutionTracer tracer = getExecutionTracer(); // logger.info("passedBranch val="+val+", opcode="+opcode+", branch="+branch+", bytecode_id="+bytecode_id); if (tracer.disabled) return; if (isThreadNeqCurrentThread()) return; checkTimeout(); ConstantPoolManager.getInstance().addDynamicConstant(val); // logger.trace("Called passedBranch1 with opcode "+AbstractVisitor.OPCODES[opcode]+" and val "+val+" in branch "+branch); double distance_true = 0.0; double distance_false = 0.0; switch (opcode) { case Opcodes.IFEQ: distance_true = Math.abs((double) val); // The greater abs is, the // further away from 0 distance_false = distance_true == 0 ? 1.0 : 0.0; // Anything but 0 // is good break; case Opcodes.IFNE: distance_false = Math.abs((double) val); // The greater abs is, the // further away from 0 distance_true = distance_false == 0 ? 1.0 : 0.0; // Anything but 0 // leads to NE break; case Opcodes.IFLT: distance_true = val >= 0 ? val + 1.0 : 0.0; // The greater, the // further away from < 0 distance_false = val < 0 ? 0.0 - val + 1.0 : 0.0; // The smaller, // the further // away from < 0 break; case Opcodes.IFGT: distance_true = val <= 0 ? 0.0 - val + 1.0 : 0.0; distance_false = val > 0 ? val + 1.0 : 0.0; break; case Opcodes.IFGE: distance_true = val < 0 ? 0.0 - val + 1.0 : 0.0; distance_false = val >= 0 ? val + 1.0 : 0.0; break; case Opcodes.IFLE: distance_true = val > 0 ? val + 1.0 : 0.0; // The greater, the // further away from < 0 distance_false = val <= 0 ? 0.0 - val + 1.0 : 0.0; // The smaller, // the further // away from < 0 break; default: logger.error("Unknown opcode: " + opcode); } // logger.trace("1 Branch distance true : " + distance_true); // logger.trace("1 Branch distance false: " + distance_false); // Add current branch to control trace tracer.trace.branchPassed(branch, bytecode_id, distance_true, distance_false); }
From source file:org.evosuite.testcase.ExecutionTracer.java
License:Open Source License
/** * Called by the instrumented code each time a new branch is taken * // ww w.ja v a 2s . c om * @param val * a int. * @param opcode * a int. * @param branch * a int. * @param bytecode_id * a int. */ public static void passedBranch(int val, int opcode, int branch, int bytecode_id) { ExecutionTracer tracer = getExecutionTracer(); // logger.info("passedBranch val="+val+", opcode="+opcode+", branch="+branch+", bytecode_id="+bytecode_id); if (tracer.disabled) return; if (isThreadNeqCurrentThread()) return; checkTimeout(); if (Properties.DYNAMIC_SEEDING) { ConstantPoolManager.getInstance().addDynamicConstant(val); } ; // logger.trace("Called passedBranch1 with opcode "+AbstractVisitor.OPCODES[opcode]+" and val "+val+" in branch "+branch); double distance_true = 0.0; double distance_false = 0.0; switch (opcode) { case Opcodes.IFEQ: distance_true = Math.abs((double) val); // The greater abs is, the // further away from 0 distance_false = distance_true == 0 ? 1.0 : 0.0; // Anything but 0 // is good break; case Opcodes.IFNE: distance_false = Math.abs((double) val); // The greater abs is, the // further away from 0 distance_true = distance_false == 0 ? 1.0 : 0.0; // Anything but 0 // leads to NE break; case Opcodes.IFLT: distance_true = val >= 0 ? val + 1.0 : 0.0; // The greater, the // further away from < 0 distance_false = val < 0 ? 0.0 - val + 1.0 : 0.0; // The smaller, // the further // away from < 0 break; case Opcodes.IFGT: distance_true = val <= 0 ? 0.0 - val + 1.0 : 0.0; distance_false = val > 0 ? val + 1.0 : 0.0; break; case Opcodes.IFGE: distance_true = val < 0 ? 0.0 - val + 1.0 : 0.0; distance_false = val >= 0 ? val + 1.0 : 0.0; break; case Opcodes.IFLE: distance_true = val > 0 ? val + 1.0 : 0.0; // The greater, the // further away from < 0 distance_false = val <= 0 ? 0.0 - val + 1.0 : 0.0; // The smaller, // the further // away from < 0 break; default: logger.error("Unknown opcode: {}", opcode); } // logger.trace("1 Branch distance true : " + distance_true); // logger.trace("1 Branch distance false: " + distance_false); // Add current branch to control trace tracer.trace.branchPassed(branch, bytecode_id, distance_true, distance_false); }
From source file:org.evosuite.TestSuiteGenerator.java
License:Open Source License
private void getBytecodeStatistics() { if (Properties.TRACK_BOOLEAN_BRANCHES) { int gradientBranchCount = ExecutionTraceImpl.gradientBranches.size() * 2; ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Gradient_Branches, gradientBranchCount);/*from w ww. j a v a2s .c o m*/ } if (Properties.TRACK_COVERED_GRADIENT_BRANCHES) { int coveredGradientBranchCount = ExecutionTraceImpl.gradientBranchesCoveredTrue.size() + ExecutionTraceImpl.gradientBranchesCoveredFalse.size(); ClientServices.getInstance().getClientNode() .trackOutputVariable(RuntimeVariable.Gradient_Branches_Covered, coveredGradientBranchCount); } if (Properties.BRANCH_COMPARISON_TYPES) { int cmp_intzero = 0, cmp_intint = 0, cmp_refref = 0, cmp_refnull = 0; int bc_lcmp = 0, bc_fcmpl = 0, bc_fcmpg = 0, bc_dcmpl = 0, bc_dcmpg = 0; for (Branch b : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()) .getAllBranches()) { int branchOpCode = b.getInstruction().getASMNode().getOpcode(); int previousOpcode = -2; if (b.getInstruction().getASMNode().getPrevious() != null) previousOpcode = b.getInstruction().getASMNode().getPrevious().getOpcode(); switch (previousOpcode) { case Opcodes.LCMP: bc_lcmp++; break; case Opcodes.FCMPL: bc_fcmpl++; break; case Opcodes.FCMPG: bc_fcmpg++; break; case Opcodes.DCMPL: bc_dcmpl++; break; case Opcodes.DCMPG: bc_dcmpg++; break; } switch (branchOpCode) { // copmpare int with zero case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: cmp_intzero++; break; // copmpare int with int case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: cmp_intint++; break; // copmpare reference with reference case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: cmp_refref++; break; // compare reference with null case Opcodes.IFNULL: case Opcodes.IFNONNULL: cmp_refnull++; break; } } ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Cmp_IntZero, cmp_intzero); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Cmp_IntInt, cmp_intint); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Cmp_RefRef, cmp_refref); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Cmp_RefNull, cmp_refnull); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.BC_lcmp, bc_lcmp); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.BC_fcmpl, bc_fcmpl); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.BC_fcmpg, bc_fcmpg); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.BC_dcmpl, bc_dcmpl); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.BC_dcmpg, bc_dcmpg); RuntimeVariable[] bytecodeVarsCovered = new RuntimeVariable[] { RuntimeVariable.Covered_lcmp, RuntimeVariable.Covered_fcmpl, RuntimeVariable.Covered_fcmpg, RuntimeVariable.Covered_dcmpl, RuntimeVariable.Covered_dcmpg, RuntimeVariable.Covered_IntInt, RuntimeVariable.Covered_IntInt, RuntimeVariable.Covered_IntZero, RuntimeVariable.Covered_RefRef, RuntimeVariable.Covered_RefNull }; for (RuntimeVariable bcvar : bytecodeVarsCovered) { ClientServices.getInstance().getClientNode().trackOutputVariable(bcvar, getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionCoveredFalse) + getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionCoveredTrue)); } RuntimeVariable[] bytecodeVarsReached = new RuntimeVariable[] { RuntimeVariable.Reached_lcmp, RuntimeVariable.Reached_fcmpl, RuntimeVariable.Reached_fcmpg, RuntimeVariable.Reached_dcmpl, RuntimeVariable.Reached_dcmpg, RuntimeVariable.Reached_IntInt, RuntimeVariable.Reached_IntInt, RuntimeVariable.Reached_IntZero, RuntimeVariable.Reached_RefRef, RuntimeVariable.Reached_RefNull }; for (RuntimeVariable bcvar : bytecodeVarsReached) { ClientServices.getInstance().getClientNode().trackOutputVariable(bcvar, getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionReached) * 2); } } }