def test_simpleIf(): b = ast_parse.parse(simpleIf).body p = Path(b,source=simpleIf) # Step through the "if" statement p = p.step()[0] p = p.step()[0] p2 = p.step() ifSide = p2[0] elseSide = p2[1] # ifSide's path should now be inside, meaning only the print statement assert len(ifSide.state.path) == 1 # Else should be in the else statement assert len(elseSide.state.path) == 2 # Neither have anything to do after the if statement assert len(ifSide.state.callStack) == 1 assert len(elseSide.state.callStack) == 0 # If side should not be possible assert not ifSide.state.isSat() assert elseSide.state.isSat() # Track expected number of assertions #assert len(ifSide.state.solver.assertions()) == 3 #assert len(elseSide.state.solver.assertions()) == 3 # Make sure the answer makes sense assert ifSide.state.any_int('x') == None assert elseSide.state.any_int('x') == 1
def test_simpleIf(): b = ast_parse.parse(simpleIf).body p = Path(b, source=simpleIf) # Step through the "if" statement p = p.step()[0] p = p.step()[0] p2 = p.step() ifSide = p2[0] elseSide = p2[1] # ifSide's path should now be inside, meaning only the print statement assert len(ifSide.state.path) == 1 # Else should be in the else statement assert len(elseSide.state.path) == 2 # Neither have anything to do after the if statement assert len(ifSide.state.callStack) == 1 assert len(elseSide.state.callStack) == 0 # If side should not be possible assert not ifSide.state.isSat() assert elseSide.state.isSat() # Track expected number of assertions #assert len(ifSide.state.solver.assertions()) == 3 #assert len(elseSide.state.solver.assertions()) == 3 # Make sure the answer makes sense assert ifSide.state.any_int('x') == None assert elseSide.state.any_int('x') == 1
def test_pySym_returnToAssign(): # Testing that we can return a function to a variable b = ast_parse.parse(test5).body p = Path(b,source=test5) p = p.step()[0] p = p.step()[0] p = p.step()[0] p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.any_int('x') == 5
def test_ifReturn(): b = ast_parse.parse(testIfReturn).body p = Path(b,source=testIfReturn) p = p.step()[0].step()[0] ifSide,elseSide = p.step() ifSide = ifSide.step()[0].step()[0] elseSide = elseSide.step()[0].step()[0] assert ifSide.state.any_int('x') == 2 assert ifSide.state.any_real('y') == 2.2 assert elseSide.state.any_int('x') == None assert elseSide.state.any_real('y') == None # Else side is wonky because it's not a possible path
def test_ifReturn(): b = ast_parse.parse(testIfReturn).body p = Path(b, source=testIfReturn) p = p.step()[0].step()[0] ifSide, elseSide = p.step() ifSide = ifSide.step()[0].step()[0] elseSide = elseSide.step()[0].step()[0] assert ifSide.state.any_int('x') == 2 assert ifSide.state.any_real('y') == 2.2 assert elseSide.state.any_int('x') == None assert elseSide.state.any_real( 'y') == None # Else side is wonky because it's not a possible path
def test_pySym_AugAssign_MixedTypes(): ####### # Add # ####### b = ast_parse.parse(test2).body p = Path(b,source=test2) # Step through program p = p.step()[0] p = p.step()[0] ifSide,elseSide = p.step() elseSide = elseSide.step()[0] assert elseSide.state.isSat() assert elseSide.state.any_real('x') == 9.0 assert elseSide.state.objectManager.getVar('x',ctx=elseSide.state.ctx).getZ3Object().is_real()
def test_pySym_pass(): # Testing we can pass :-) b = ast_parse.parse(test1).body p = Path(b,source=test1) p = p.step()[0] p = p.step()[0] assert p.state.any_int('x') == 4 assert len(p.state.backtrace) == 2
def test_pathCopy(): b = ast_parse.parse(test1).body p = Path(b, source=test1) p2 = p.copy() assert p2 != p p = p.step()[0] assert p.state.any_int('x') == 1 with pytest.raises(Exception): p2.state.any_int('x')
def test_pySym_FuncionDef(): b = ast_parse.parse(test1).body p = Path(b,source=test1) # Step through program p = p.step()[0] p = p.step()[0] # We should have two defs now assert "test" in p.state.functions assert "test2" in p.state.functions
def test_pySym_FuncionDef(): b = ast_parse.parse(test1).body p = Path(b, source=test1) # Step through program p = p.step()[0] p = p.step()[0] # We should have two defs now assert "test" in p.state.functions assert "test2" in p.state.functions
def test_pySym_pass(): # Testing we can pass :-) b = ast_parse.parse(test1).body p = Path(b, source=test1) p = p.step()[0] p = p.step()[0] assert p.state.any_int('x') == 4 assert len(p.state.backtrace) == 2
def test_pathCopy(): b = ast_parse.parse(test1).body p = Path(b,source=test1) p2 = p.copy() assert p2 != p p = p.step()[0] assert p.state.any_int('x') == 1 with pytest.raises(Exception): p2.state.any_int('x')
def test_mixedTypes(): b = ast_parse.parse(test3).body p = Path(b, source=test3) # Step through program p = p.step()[0] p = p.step()[0] print(p.state.solver) print(p.state.isSat()) assert p.state.isSat() assert p.state.any_real('x') == 5.5
def test_mixedTypes(): b = ast_parse.parse(test3).body p = Path(b,source=test3) # Step through program p = p.step()[0] p = p.step()[0] print(p.state.solver) print(p.state.isSat()) assert p.state.isSat() assert p.state.any_real('x') == 5.5
def test_basicPathStep(): b = ast_parse.parse(test1).body p1 = Path(b,source=test1) p2 = p1.step()[0].step()[0] p1.printBacktrace() p2.printBacktrace() assert p2.state.any_int('x') == 1 assert p2.state.any_int('y') == 2 with pytest.raises(Exception): p1.state.any_int('x') with pytest.raises(Exception): p1.state.any_int('y')
def test_basicPathStep(): b = ast_parse.parse(test1).body p1 = Path(b, source=test1) p2 = p1.step()[0].step()[0] p1.printBacktrace() p2.printBacktrace() assert p2.state.any_int('x') == 1 assert p2.state.any_int('y') == 2 with pytest.raises(Exception): p1.state.any_int('x') with pytest.raises(Exception): p1.state.any_int('y')
def test_pySym_AugAssign(): ####### # Add # ####### b = ast_parse.parse(test1.format("+=")).body p = Path(b,source=test1.format("+=")) # Step through program p = p.step()[0] p = p.step()[0] ifSide,elseSide = p.step() elseSide = elseSide.step()[0] assert elseSide.state.isSat() assert elseSide.state.any_int('x') == 14 ############ # Subtract # ############ b = ast_parse.parse(test1.format("-=")).body p = Path(b,source=test1.format("-=")) # Step through program p = p.step()[0] p = p.step()[0] ifSide,elseSide = p.step() elseSide = elseSide.step()[0] assert elseSide.state.isSat() assert elseSide.state.any_int('x') == 0 ############ # Multiply # ############ b = ast_parse.parse(test1.format("*=")).body p = Path(b,source=test1.format("*=")) # Step through program p = p.step()[0] p = p.step()[0] ifSide,elseSide = p.step() elseSide = elseSide.step()[0] assert elseSide.state.isSat() assert elseSide.state.any_int('x') == 49 ########## # Divide # ########## b = ast_parse.parse(test1.format("/=")).body p = Path(b,source=test1.format("/=")) # Step through program p = p.step()[0] p = p.step()[0] ifSide,elseSide = p.step() elseSide = elseSide.step()[0] assert elseSide.state.isSat() assert elseSide.state.any_int('x') == 1 ########## # Modulo # ########## b = ast_parse.parse(test1.format("%=")).body p = Path(b,source=test1.format("%=")) # Step through program p = p.step()[0] p = p.step()[0] ifSide,elseSide = p.step() elseSide = elseSide.step()[0] assert elseSide.state.isSat() assert elseSide.state.any_int('x') == 0
def test_pySym_Compare(): ################ # Greater Than # ################ b = ast_parse.parse(compare1.format(1,5,">")).body p = Path(b,source=compare1.format(1,5,">")) # Step through the "if" statement p = p.step()[0] p = p.step()[0] p2 = p.step() ifSide = p2[0] elseSide = p2[1] # If side should not be possible assert not ifSide.state.isSat() assert elseSide.state.isSat() # Track expected number of assertions #assert len(ifSide.state.solver.assertions()) == 3 #assert len(elseSide.state.solver.assertions()) == 3 # Make sure the answer makes sense assert ifSide.state.any_int('x') == None assert elseSide.state.any_int('x') == 1 ######################### # Greater Than Or Equal # ######################### b = ast_parse.parse(compare1.format(2,2,">=")).body p = Path(b,source=compare1.format(2,2,">=")) # Step through the "if" statement p = p.step()[0] p = p.step()[0] p2 = p.step() ifSide = p2[0] elseSide = p2[1] # If side should be correct assert ifSide.state.isSat() assert not elseSide.state.isSat() # Track expected number of assertions #assert len(ifSide.state.solver.assertions()) == 3 #assert len(elseSide.state.solver.assertions()) == 3 # Make sure the answer makes sense assert ifSide.state.any_int('x') == 2 assert elseSide.state.any_int('x') == None ############# # Less Than # ############# b = ast_parse.parse(compare1.format(1,5,"<")).body p = Path(b,source=compare1.format(1,5,"<")) # Step through the "if" statement p = p.step()[0] p = p.step()[0] p2 = p.step() ifSide = p2[0] elseSide = p2[1] # If side should be correct assert ifSide.state.isSat() assert not elseSide.state.isSat() # Track expected number of assertions #assert len(ifSide.state.solver.assertions()) == 3 #assert len(elseSide.state.solver.assertions()) == 3 # Make sure the answer makes sense assert ifSide.state.any_int('x') == 1 assert elseSide.state.any_int('x') == None ###################### # Less Than Or Equal # ###################### b = ast_parse.parse(compare1.format(3,5,"<=")).body p = Path(b,source=compare1.format(3,5,"<=")) # Step through the "if" statement p = p.step()[0] p = p.step()[0] p2 = p.step() ifSide = p2[0] elseSide = p2[1] # If side should be correct assert ifSide.state.isSat() assert not elseSide.state.isSat() # Track expected number of assertions #assert len(ifSide.state.solver.assertions()) == 3 #assert len(elseSide.state.solver.assertions()) == 3 # Make sure the answer makes sense assert ifSide.state.any_int('x') == 3 assert elseSide.state.any_int('x') == None ######### # Equal # ######### b = ast_parse.parse(compare1.format(1,5,"==")).body p = Path(b,source=compare1.format(1,5,"==")) # Step through the "if" statement p = p.step()[0] p = p.step()[0] p2 = p.step() ifSide = p2[0] elseSide = p2[1] # If side should not be correct assert not ifSide.state.isSat() assert elseSide.state.isSat() # Track expected number of assertions #assert len(ifSide.state.solver.assertions()) == 3 #assert len(elseSide.state.solver.assertions()) == 3 # Make sure the answer makes sense assert ifSide.state.any_int('x') == None assert elseSide.state.any_int('x') == 1 ############# # Not Equal # ############# b = ast_parse.parse(compare1.format(1,5,"!=")).body p = Path(b,source=compare1.format(1,5,"!=")) # Step through the "if" statement p = p.step()[0] p = p.step()[0] p2 = p.step() ifSide = p2[0] elseSide = p2[1] # If side should be correct assert ifSide.state.isSat() assert not elseSide.state.isSat() # Track expected number of assertions #assert len(ifSide.state.solver.assertions()) == 3 #assert len(elseSide.state.solver.assertions()) == 3 # Make sure the answer makes sense assert ifSide.state.any_int('x') == 1 assert elseSide.state.any_int('x') == None
def test_pySym_BinOp(): ####### # Add # ####### b = ast_parse.parse(test1.format("+")).body p = Path(b, source=test1.format("+")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_real('x') == 4.0 ####### # Sub # ####### b = ast_parse.parse(test1.format("-")).body p = Path(b, source=test1.format("-")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_real('x') == -1.0 ####### # Mul # ####### b = ast_parse.parse(test1.format("*")).body p = Path(b, source=test1.format("*")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_real('x') == 3.75 ####### # Div # ####### b = ast_parse.parse(test1.format("/")).body p = Path(b, source=test1.format("/")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_real('x') == 0.6 ####### # Mod # ####### b = ast_parse.parse(test2.format("%")).body p = Path(b, source=test2.format("%")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_int('x') == 2
def test_pySym_BinOp(): ####### # Add # ####### b = ast_parse.parse(test1.format("+")).body p = Path(b,source=test1.format("+")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_real('x') == 4.0 ####### # Sub # ####### b = ast_parse.parse(test1.format("-")).body p = Path(b,source=test1.format("-")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_real('x') == -1.0 ####### # Mul # ####### b = ast_parse.parse(test1.format("*")).body p = Path(b,source=test1.format("*")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_real('x') == 3.75 ####### # Div # ####### b = ast_parse.parse(test1.format("/")).body p = Path(b,source=test1.format("/")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_real('x') == 0.6 ####### # Mod # ####### b = ast_parse.parse(test2.format("%")).body p = Path(b,source=test2.format("%")) # Step through program p = p.step()[0] p = p.step()[0] p = p.step()[0] assert p.state.isSat() assert p.state.any_int('x') == 2