use of soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet in project soot by Sable.
the class UnitThrowAnalysisTest method testJAssignStmt.
@Test
public void testJAssignStmt() {
// local0 = 0
Stmt s = Jimple.v().newAssignStmt(Jimple.v().newLocal("local0", IntType.v()), IntConstant.v(0));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(s)));
ArrayRef arrayRef = Jimple.v().newArrayRef(Jimple.v().newLocal("local1", ArrayType.v(RefType.v("java.lang.Object"), 1)), IntConstant.v(0));
Local scalarRef = Jimple.v().newLocal("local2", RefType.v("java.lang.Object"));
// local2 = local1[0]
s = Jimple.v().newAssignStmt(scalarRef, arrayRef);
Set<RefLikeType> expectedRep = new ExceptionHashSet<RefLikeType>(utility.VM_ERRORS);
expectedRep.add(utility.NULL_POINTER_EXCEPTION);
expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.<AnySubType>emptySet(), unitAnalysis.mightThrow(s)));
Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION);
expectedCatch.add(utility.RUNTIME_EXCEPTION);
expectedCatch.add(utility.EXCEPTION);
assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(s)));
// local1[0] = local2
s = Jimple.v().newAssignStmt(arrayRef, scalarRef);
expectedRep.add(utility.ARRAY_STORE_EXCEPTION);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
expectedCatch.add(utility.ARRAY_STORE_EXCEPTION);
assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
use of soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet in project soot by Sable.
the class UnitThrowAnalysisTest method testGDivExpr.
@Test
public void testGDivExpr() {
Set vmAndArithmetic = new ExceptionHashSet(utility.VM_ERRORS);
vmAndArithmetic.add(utility.ARITHMETIC_EXCEPTION);
Set vmAndArithmeticAndSupertypes = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
vmAndArithmeticAndSupertypes.add(utility.ARITHMETIC_EXCEPTION);
vmAndArithmeticAndSupertypes.add(utility.RUNTIME_EXCEPTION);
vmAndArithmeticAndSupertypes.add(utility.EXCEPTION);
Local intLocal = Grimp.v().newLocal("intLocal", IntType.v());
Local longLocal = Grimp.v().newLocal("longLocal", LongType.v());
Local floatLocal = Grimp.v().newLocal("floatLocal", FloatType.v());
Local doubleLocal = Grimp.v().newLocal("doubleLocal", DoubleType.v());
DivExpr v = Grimp.v().newDivExpr(intLocal, IntConstant.v(0));
assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(intLocal, IntConstant.v(2));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(IntConstant.v(0), IntConstant.v(2));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(intLocal, intLocal);
assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(Grimp.v().newAddExpr(intLocal, intLocal), Grimp.v().newMulExpr(intLocal, intLocal));
assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(longLocal, LongConstant.v(0));
assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(longLocal, LongConstant.v(2));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(LongConstant.v(0), LongConstant.v(2));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(longLocal, longLocal);
assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(Grimp.v().newAddExpr(longLocal, longLocal), Grimp.v().newMulExpr(longLocal, longLocal));
assertTrue(ExceptionTestUtility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(vmAndArithmeticAndSupertypes, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(floatLocal, FloatConstant.v(0.0f));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(floatLocal, FloatConstant.v(2.0f));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(FloatConstant.v(0), FloatConstant.v(2.0f));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(floatLocal, floatLocal);
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(doubleLocal, DoubleConstant.v(0.0));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(doubleLocal, DoubleConstant.v(2.0));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(DoubleConstant.v(0), DoubleConstant.v(2.0));
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
v = Grimp.v().newDivExpr(doubleLocal, doubleLocal);
assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(v)));
}
use of soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet in project soot by Sable.
the class UnitThrowAnalysisTest method testGCastExpr.
@Test
public void testGCastExpr() {
// First an upcast that can be statically proved safe.
Value v = Grimp.v().newCastExpr(Jimple.v().newLocal("local", utility.INCOMPATIBLE_CLASS_CHANGE_ERROR), utility.LINKAGE_ERROR);
Set expectedRep = new ExceptionHashSet(utility.VM_AND_RESOLVE_CLASS_ERRORS_REP);
Set expectedCatch = new ExceptionHashSet(utility.VM_AND_RESOLVE_CLASS_ERRORS_PLUS_SUPERTYPES);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(v)));
// Then a vacuous cast which can be statically proved safe.
v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", utility.LINKAGE_ERROR), utility.LINKAGE_ERROR);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(v)));
// Finally a downcast which is not necessarily safe:
v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", utility.LINKAGE_ERROR), utility.INCOMPATIBLE_CLASS_CHANGE_ERROR);
expectedRep.add(utility.CLASS_CAST_EXCEPTION);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
expectedCatch.add(utility.CLASS_CAST_EXCEPTION);
expectedCatch.add(utility.RUNTIME_EXCEPTION);
expectedCatch.add(utility.EXCEPTION);
assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(v)));
}
use of soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet in project soot by Sable.
the class UnitThrowAnalysisTest method testGEnterMonitorStmt.
@Test
public void testGEnterMonitorStmt() {
Stmt s = Grimp.v().newEnterMonitorStmt(StringConstant.v("test"));
Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
expectedRep.add(utility.NULL_POINTER_EXCEPTION);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
expectedCatch.add(utility.RUNTIME_EXCEPTION);
expectedCatch.add(utility.EXCEPTION);
assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
use of soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet in project soot by Sable.
the class UnitThrowAnalysisTest method testJCastExpr.
@Test
public void testJCastExpr() {
// First an upcast that can be statically proved safe.
Value v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", utility.INCOMPATIBLE_CLASS_CHANGE_ERROR), utility.LINKAGE_ERROR);
Set expectedRep = new ExceptionHashSet(utility.VM_AND_RESOLVE_CLASS_ERRORS_REP);
Set expectedCatch = new ExceptionHashSet(utility.VM_AND_RESOLVE_CLASS_ERRORS_PLUS_SUPERTYPES);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(v)));
// Then a vacuous cast which can be statically proved safe.
v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", utility.LINKAGE_ERROR), utility.LINKAGE_ERROR);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(v)));
// Finally a downcast which is not necessarily safe:
v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", utility.LINKAGE_ERROR), utility.INCOMPATIBLE_CLASS_CHANGE_ERROR);
expectedRep.add(utility.CLASS_CAST_EXCEPTION);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET, unitAnalysis.mightThrow(v)));
expectedCatch.add(utility.CLASS_CAST_EXCEPTION);
expectedCatch.add(utility.RUNTIME_EXCEPTION);
expectedCatch.add(utility.EXCEPTION);
assertEquals(expectedCatch, utility.catchableSubset(unitAnalysis.mightThrow(v)));
}
Aggregations