Exemplo n.º 1
0
def test_global_not_found() -> None:
    line = 'addr bogus'

    with pytest.raises(sdb.SymbolNotFoundError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert err.value.symbol == 'bogus'
Exemplo n.º 2
0
def test_dot_with_no_identifier() -> None:
    line = 'addr global_cstruct | member cs_struct.'

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert "no identifier specified after ." in str(err.value)
Exemplo n.º 3
0
def test_member_not_found() -> None:
    line = 'addr global_struct | member bogus'

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert "'struct test_struct' has no member 'bogus'" in str(err.value)
Exemplo n.º 4
0
def test_array_member_incomplete_expression() -> None:
    line = 'addr global_struct | member ts_array[2'

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert "incomplete array expression" in str(err.value)
Exemplo n.º 5
0
def test_array_member_bogus_index() -> None:
    line = 'addr global_struct | member ts_array[a]'

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert "incorrect index: 'a' is not a number" in str(err.value)
Exemplo n.º 6
0
def test_scalar_input() -> None:
    line = 'addr global_int | member int_member'

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert "'int' is not a structure, union, or class" in str(err.value)
Exemplo n.º 7
0
def test_pointer_to_struct() -> None:
    line = 'addr global_int | cast struct test_struct'

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert "cannot convert 'int *' to 'struct test_struct'" in str(err.value)
Exemplo n.º 8
0
def test_str_pipe_input_pointer_to_invalid_type() -> None:
    line = 'addr global_int | cast bogus'

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert "could not find type 'bogus'" in str(err.value)
Exemplo n.º 9
0
def test_arg_no_pipe_input_invalid_type() -> None:
    line = 'cast bogus'

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert "could not find type 'bogus'" in str(err.value)
Exemplo n.º 10
0
def test_embedded_struct_member_deref_notation_error() -> None:
    line = 'addr global_cstruct | member cs_struct->ts_int'

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert "use the dot(.) notation for member access" in str(err.value)
Exemplo n.º 11
0
def test_bogus_arg() -> None:
    line = 'echo bogus'

    with pytest.raises(sdb.CommandInvalidInputError) as err:
        invoke(MOCK_PROGRAM, [], line)

    assert err.value.argument == 'bogus'
Exemplo n.º 12
0
def test_arrow_with_no_identifier():
    line = 'addr global_cstruct | member cs_struct->'
    objs = []

    with pytest.raises(sdb.CommandError) as err:
        invoke(MOCK_PROGRAM, objs, line)

    assert "no identifier specified after ->" in str(err.value)
Exemplo n.º 13
0
def test_arg_no_pipe_input():
    line = 'cast int'
    objs = []

    ret = invoke(MOCK_PROGRAM, objs, line)

    assert not ret
Exemplo n.º 14
0
def test_multiple_piped_inputs() -> None:
    line = 'echo 0x0 0xfffff 0xdeadbeef 0x101010 | count'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].value_() == 4
Exemplo n.º 15
0
def test_single_piped_input() -> None:
    line = 'echo 0x0 | count'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].value_() == 1
Exemplo n.º 16
0
def test_empty() -> None:
    line = 'count'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].value_() == 0
Exemplo n.º 17
0
def test_empty():
    line = 'echo'
    objs = []

    ret = invoke(MOCK_PROGRAM, objs, line)

    assert not ret
Exemplo n.º 18
0
def test_plain_address() -> None:
    line = 'addr 0xffffffffc084eee0'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].value_() == 0xffffffffc084eee0
    assert sdb.type_equals(ret[0].type_, MOCK_PROGRAM.type('void *'))
Exemplo n.º 19
0
def test_single_arg() -> None:
    line = 'echo 1'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].value_() == 1
    assert ret[0].type_ == MOCK_PROGRAM.type('void *')
Exemplo n.º 20
0
def test_single_arg_decimal() -> None:
    line = 'echo 0'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].value_() == 0
    assert sdb.type_equals(ret[0].type_, MOCK_PROGRAM.type('void *'))
Exemplo n.º 21
0
def test_single_input():
    line = 'count'
    objs = [drgn.Object(MOCK_PROGRAM, 'void *', value=0)]

    ret = invoke(MOCK_PROGRAM, objs, line)

    assert len(ret) == 1
    assert ret[0].value_() == 1
Exemplo n.º 22
0
def test_single_piped_input():
    line = 'echo 0x0 | count'
    objs = []

    ret = invoke(MOCK_PROGRAM, objs, line)

    assert len(ret) == 1
    assert ret[0].value_() == 1
Exemplo n.º 23
0
def test_single_object() -> None:
    line = 'addr global_int'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].value_() == 0xffffffffc0000000
    assert sdb.type_equals(ret[0].type_, MOCK_PROGRAM.type('int *'))
Exemplo n.º 24
0
def test_double_cast() -> None:
    line = 'addr global_int | cast unsigned int | cast char *'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].type_ == MOCK_PROGRAM.type('char *')
    assert ret[0].value_() == 0xc0000000
Exemplo n.º 25
0
def test_empty():
    line = 'count'
    objs = []

    ret = invoke(MOCK_PROGRAM, objs, line)

    assert len(ret) == 1
    assert ret[0].value_() == 0
Exemplo n.º 26
0
def test_pipe_input_pointer_to_int() -> None:
    line = 'addr global_int | cast unsigned int'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].type_ == MOCK_PROGRAM.type('unsigned int')
    assert ret[0].value_() == 0xc0000000
Exemplo n.º 27
0
def test_str_pipe_input() -> None:
    line = 'addr global_int | cast void *'

    ret = invoke(MOCK_PROGRAM, [], line)

    assert len(ret) == 1
    assert ret[0].type_ == MOCK_PROGRAM.type('void *')
    assert ret[0].value_() == 0xffffffffc0000000
Exemplo n.º 28
0
def test_test_piped_int():
    line = 'echo'
    objs = [drgn.Object(MOCK_PROGRAM, 'int', value=1)]

    ret = invoke(MOCK_PROGRAM, objs, line)

    assert len(ret) == 1
    assert ret[0].value_() == 1
    assert ret[0].type_ == MOCK_PROGRAM.type('int')
Exemplo n.º 29
0
def test_single_arg():
    line = 'echo 1'
    objs = []

    ret = invoke(MOCK_PROGRAM, objs, line)

    assert len(ret) == 1
    assert ret[0].value_() == 1
    assert ret[0].type_ == MOCK_PROGRAM.type('void *')
Exemplo n.º 30
0
def test_invoke_pipe_input() -> None:
    line = 'cast void *'
    objs = [MOCK_PROGRAM['global_int']]

    ret = invoke(MOCK_PROGRAM, objs, line)

    assert len(ret) == 1
    assert ret[0].type_ == MOCK_PROGRAM.type('void *')
    assert ret[0].value_() == 0x01020304