def test_echo_pipe(): line = 'addr 0xffffffffc084eee0 | addr global_void_ptr' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 2 assert ret[0].value_() == 0xffffffffc084eee0 assert ret[0].type_ == MOCK_PROGRAM.type('void *') assert ret[1].value_() == 0xffff88d26353c108 assert ret[1].type_ == MOCK_PROGRAM.type('void **')
def test_multiple_args(): line = 'echo 0 1' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 2 assert ret[0].value_() == 0 assert ret[0].type_ == MOCK_PROGRAM.type('void *') assert ret[1].value_() == 1 assert ret[1].type_ == MOCK_PROGRAM.type('void *')
def test_multiple_object(): line = 'addr global_int 0xffffffffc084eee0 global_void_ptr' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 3 assert ret[0].value_() == 0xffffffffc0000000 assert ret[0].type_ == MOCK_PROGRAM.type('int *') assert ret[1].value_() == 0xffffffffc084eee0 assert ret[1].type_ == MOCK_PROGRAM.type('void *') assert ret[2].value_() == 0xffff88d26353c108 assert ret[2].type_ == MOCK_PROGRAM.type('void **')
def test_piped_invocations(): line = 'addr global_int | addr 0xffffffffc084eee0 global_void_ptr' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 3 assert ret[0].value_() == 0xffffffffc0a8aee0 assert ret[0].type_ == MOCK_PROGRAM.type('int *') assert ret[1].value_() == 0xffffffffc084eee0 assert ret[1].type_ == MOCK_PROGRAM.type('void *') assert ret[2].value_() == 0xffff88d26353c108 assert ret[2].type_ == MOCK_PROGRAM.type('void **')
def test_multiple_piped(): line = 'echo' objs = [ drgn.Object(MOCK_PROGRAM, 'void *', value=0), drgn.Object(MOCK_PROGRAM, 'int', value=1), ] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 2 assert ret[0].value_() == 0 assert ret[0].type_ == MOCK_PROGRAM.type('void *') assert ret[1].value_() == 1 assert ret[1].type_ == MOCK_PROGRAM.type('int')
def test_multi_void_ptr_input_value_match_le(): line = 'filter obj <= 1' objs = [ drgn.Object(MOCK_PROGRAM, 'void *', value=0), drgn.Object(MOCK_PROGRAM, 'void *', value=1), drgn.Object(MOCK_PROGRAM, 'void *', value=2), ] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 2 assert ret[0].value_() == 0 assert ret[0].type_ == MOCK_PROGRAM.type('void *') assert ret[1].value_() == 1 assert ret[1].type_ == MOCK_PROGRAM.type('void *')
def test_plain_address(): line = 'addr 0xffffffffc084eee0' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0].value_() == 0xffffffffc084eee0 assert ret[0].type_ == MOCK_PROGRAM.type('void *')
def test_single_object(): line = 'addr global_int' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0].value_() == 0xffffffffc0a8aee0 assert ret[0].type_ == MOCK_PROGRAM.type('int *')
def test_single_void_ptr_input_value_match(): line = 'filter obj == 0' objs = [drgn.Object(MOCK_PROGRAM, 'void *', value=0)] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0].value_() == 0 assert ret[0].type_ == MOCK_PROGRAM.type('void *')
def test_struct_input_int_member_match_le(): line = 'filter obj.ts_int <= 1' objs = [MOCK_PROGRAM["global_struct"]] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0].type_ == MOCK_PROGRAM.type('struct test_struct') assert ret[0].address_of_().value_() == 0xffffffffc0a8aee0
def test_double_cast(): line = 'addr global_int | cast unsigned int | cast char *' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0].type_ == MOCK_PROGRAM.type('char *') assert ret[0].value_() == 0xc0000000
def test_str_pipe_input(): line = 'addr global_int | cast void *' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0].type_ == MOCK_PROGRAM.type('void *') assert ret[0].value_() == 0xffffffffc0000000
def test_pipe_input_pointer_to_int(): line = 'addr global_int | cast unsigned int' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0].type_ == MOCK_PROGRAM.type('unsigned int') assert ret[0].value_() == 0xc0000000
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')
def test_invoke_pipe_input(): 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
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 *')
def test_piped_input(): line = 'echo' objs = [drgn.Object(MOCK_PROGRAM, 'void *', value=0)] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0].value_() == 0 assert ret[0].type_ == MOCK_PROGRAM.type('void *')
def test_piped_and_args_combo(): line = 'echo 0 1' objs = [ drgn.Object(MOCK_PROGRAM, 'void *', value=0), drgn.Object(MOCK_PROGRAM, 'int', value=1), ] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 4 assert ret[0].value_() == 0 assert ret[0].type_ == MOCK_PROGRAM.type('void *') assert ret[1].value_() == 1 assert ret[1].type_ == MOCK_PROGRAM.type('int') assert ret[2].value_() == 0 assert ret[2].type_ == MOCK_PROGRAM.type('void *') assert ret[3].value_() == 1 assert ret[3].type_ == MOCK_PROGRAM.type('void *')
def test_array_member_index(): line = 'addr global_struct | member ts_array[0]' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0] == drgn.Object(MOCK_PROGRAM, MOCK_PROGRAM.type('int'), value=0x0f0f0f0f)
def test_char_array_input_string_match(): line = 'filter obj == "foo"' objs = [drgn.Object(MOCK_PROGRAM, 'char [4]', value=b"foo")] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0].value_() == [102, 111, 111, 0] assert ret[0].string_() == b'foo' assert ret[0].type_ == MOCK_PROGRAM.type('char [4]')
def test_one_member(): line = 'addr global_struct | member ts_int' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 1 assert ret[0] == drgn.Object(MOCK_PROGRAM, MOCK_PROGRAM.type('int'), value=1)
def test_multi_echo_combo(): line = 'echo 2 3 | echo 4' objs = [ drgn.Object(MOCK_PROGRAM, 'void *', value=0), drgn.Object(MOCK_PROGRAM, 'int', value=1), ] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 5 assert ret[0].value_() == 0 assert ret[0].type_ == MOCK_PROGRAM.type('void *') assert ret[1].value_() == 1 assert ret[1].type_ == MOCK_PROGRAM.type('int') assert ret[2].value_() == 2 assert ret[2].type_ == MOCK_PROGRAM.type('void *') assert ret[3].value_() == 3 assert ret[3].type_ == MOCK_PROGRAM.type('void *') assert ret[4].value_() == 4 assert ret[4].type_ == MOCK_PROGRAM.type('void *')
def test_multiple_members(): line = 'addr global_struct | member ts_int ts_voidp' objs = [] ret = invoke(MOCK_PROGRAM, objs, line) assert len(ret) == 2 assert ret[0] == drgn.Object(MOCK_PROGRAM, MOCK_PROGRAM.type('int'), value=1) assert ret[1] == MOCK_PROGRAM['global_int'].address_of_()