コード例 #1
0
ファイル: test_path.py プロジェクト: Owlz/pySym
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
ファイル: test_path.py プロジェクト: Owlz/pySym
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
コード例 #5
0
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
コード例 #6
0
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()
コード例 #7
0
ファイル: test_pyState_Pass.py プロジェクト: Owlz/pySym
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
コード例 #8
0
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')
コード例 #9
0
ファイル: test_pyState_FuncionDef.py プロジェクト: Owlz/pySym
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
コード例 #10
0
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
コード例 #11
0
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
コード例 #12
0
ファイル: test_path.py プロジェクト: Owlz/pySym
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')
コード例 #13
0
ファイル: test_pyState_BinOp.py プロジェクト: pbehnke/pySym
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
コード例 #14
0
ファイル: test_pyState_BinOp.py プロジェクト: Owlz/pySym
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
コード例 #15
0
ファイル: test_path.py プロジェクト: Owlz/pySym
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')
コード例 #16
0
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')
コード例 #17
0
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
コード例 #18
0
ファイル: test_pyState_Compare.py プロジェクト: pbehnke/pySym
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
コード例 #19
0
ファイル: test_pyState_BinOp.py プロジェクト: pbehnke/pySym
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
コード例 #20
0
ファイル: test_pyState_BinOp.py プロジェクト: Owlz/pySym
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