def test_types(debugger): def test_types_cb(): check_type(debugger, "varInt", "int", TypeCategory.Builtin, BasicTypeCategory.Int) check_type(debugger, "varUnsignedShort", "unsigned short", TypeCategory.Builtin, BasicTypeCategory.UnsignedShort) check_type(debugger, "varFloat", "float", TypeCategory.Builtin, BasicTypeCategory.Float) check_type(debugger, "varClassA", "classA", TypeCategory.Class) check_type(debugger, "varStructA", "structA", TypeCategory.Struct) check_type(debugger, "varUnionA", "unionA", TypeCategory.Union) check_type(debugger, "varEnumA", "enumA", TypeCategory.Enumeration) check_type(debugger, "varEnumB", "enumB", TypeCategory.Enumeration) type = check_type(debugger, "varVector", lambda name: name.startswith("std::vector<int>"), TypeCategory.Vector) assert type.child_type.name == "int" check_type(debugger, "varString", "std::string", TypeCategory.String) type = check_type(debugger, "varArray", "int [10]", TypeCategory.Array) assert type.count == 10 assert type.child_type.name == "int" check_type(debugger, "varPointer", "int *", TypeCategory.Pointer) check_type(debugger, "varReference", "int &", TypeCategory.Reference) check_type(debugger, "varFunctionPointer", "void (*)(void)", TypeCategory.Function) setup_debugger(debugger, TEST_FILE, TEST_LINE, test_types_cb)
def test_values(debugger): def test_values_cb(): check_variable(debugger, "a", "5", int_size) check_variable(debugger, "b", "5.5", int_size) check_variable(debugger, "c", "true", 1) check_variable(debugger, "d", "hello") var = check_variable(debugger, "e") assert var.data_address == var.address assert var.max_size == 10 arr_item = debugger.variable_manager.get_variable("e[2]") assert arr_item.value == "3" assert var.get_index_by_address(arr_item.address) == 2 check_variable(debugger, "strA.x", "5", int_size) vec = debugger.variable_manager.get_variable("vec") vec.count = vec.max_size debugger.variable_manager.get_vector_items(vec) assert map(lambda child: int(child.value), vec.children) == [1, 2, 3] vec_item = debugger.variable_manager.get_variable( "*((({}){}) + 2)".format(vec.type.child_type.name, vec.data_address)) assert vec_item.value == "3" assert vec.get_index_by_address(vec_item.address) == 2 assert vec.data_address != vec.address setup_debugger(debugger, TEST_FILE, TEST_LINE, test_values_cb)
def test_function_pointer(debugger): def test_function_pointer_cb(): fn_pointer = debugger.variable_manager.get_variable("fn_pointer") assert fn_pointer.type.name == "int (*)(int, float)" assert re.match("0x(\w)+ <test\(int, float\)>", fn_pointer.value) setup_debugger(debugger, TEST_FILE, TEST_LINE, test_function_pointer_cb)
def test_address_with_code(debugger): def test_address_with_code_cb(): line_address = debugger.file_manager.get_line_address(SRC_FILE, 3) assert isinstance(line_address, tuple) assert len(line_address) == 2 assert int(line_address[0], 16) < int(line_address[1], 16) setup_debugger(debugger, TEST_FILE, 3, test_address_with_code_cb)
def test_union(debugger): def test_union_cb(): uniA = debugger.variable_manager.get_variable("uniA") assert uniA.children[0].value == "5" assert uniA.children[0].value == uniA.children[1].value assert uniA.children[0].address == uniA.children[1].address setup_debugger(debugger, TEST_FILE, TEST_LINE, test_union_cb)
def test_frame_select(debugger): def test_frame_select_cb(): assert debugger.thread_manager.change_frame(1) frame = debugger.thread_manager.get_current_frame(False) assert frame.func == "main" setup_debugger(debugger, TEST_FILE, TEST_LINE, test_frame_select_cb)
def test_pause(debugger): def test_pause_cb(): debugger.quit_program() setup_debugger(debugger, TEST_FILE, [], test_pause_cb, cont=False, wait=False) time.sleep(0.5) debugger.exec_pause()
def test_enum(debugger): def test_enum_cb(): enumA = debugger.variable_manager.get_variable("enumA") assert enumA.value == "A" enumB = debugger.variable_manager.get_variable("enumB") assert enumB.value == "EnumB::B" setup_debugger(debugger, TEST_FILE, TEST_LINE, test_enum_cb)
def test_get_memory(debugger): def test_get_memory_cb(): var = debugger.variable_manager.get_variable("a") assert [5, 0, 0, 0] == debugger.variable_manager.get_memory( var.address, var.type.size) assert len(debugger.variable_manager.get_memory(var.address, 128)) == 128 setup_debugger(debugger, TEST_FILE, TEST_LINE, test_get_memory_cb)
def test_frame_locals(debugger): def test_frame_locals_cb(): frame = debugger.thread_manager.get_current_frame(True) assert len(frame.variables) == 4 var_names = [var.name for var in frame.variables] assert set(var_names) == {"a", "b", "c", "d"} setup_debugger(debugger, TEST_FILE, TEST_LINE, test_frame_locals_cb)
def test_thread_switch(debugger): def test_thread_switch_cb(): selected = select_other_thread(debugger) thread_info = debugger.thread_manager.get_thread_info() assert thread_info.selected_thread.id == selected.id debugger.quit_program() setup_debugger(debugger, TEST_FILE, TEST_LINE, test_thread_switch_cb, cont=False)
def test_thread_info(debugger): def test_thread_info_cb(): thread_info = debugger.thread_manager.get_thread_info() assert len(thread_info.threads) == 2 assert thread_info.selected_thread.id == 1 debugger.quit_program() setup_debugger(debugger, TEST_FILE, TEST_LINE, test_thread_info_cb, cont=False)
def test_thread_location(debugger): def test_thread_location_cb(): assert debugger.file_manager.get_current_location()[1] in range(27, 35) select_other_thread(debugger) assert debugger.file_manager.get_current_location()[1] in range(9, 18) debugger.quit_program() setup_debugger(debugger, TEST_FILE, TEST_LINE, test_thread_location_cb, cont=False)
def test_frame_properties(debugger): def test_frame_properties_cb(): frame = debugger.thread_manager.get_current_frame(False) assert frame.file == os.path.abspath("src/{}.cpp".format(TEST_FILE)) assert frame.line == TEST_LINE assert frame.func == "test" assert frame.level == 0 assert len(frame.variables) == 0 setup_debugger(debugger, TEST_FILE, TEST_LINE, test_frame_properties_cb)
def test_alloc(debugger): heap = [] debugger.heap_manager.on_heap_change.subscribe(lambda new_heap: heap.append( copy.copy(new_heap))) def test_alloc_cb(): assert len(heap[0]) == 1 assert heap[0][0].size == 1024 assert len(heap[1]) == 0 setup_debugger(debugger, TEST_FILE, TEST_LINE, test_alloc_cb)
def test_step_in(debugger): state = AsyncState() def test_step_in_cb(): if state.state == 0: state.inc() debugger.exec_step_in() else: assert debugger.file_manager.get_current_location() ==\ make_location(5) debugger.quit_program() setup_debugger(debugger, TEST_FILE, 11, test_step_in_cb, cont=False)
def test_continue(debugger): state = AsyncState() def test_continue_cb(): if state.state == 0: state.inc() debugger.exec_continue() else: assert debugger.file_manager.get_current_location() ==\ make_location(13) debugger.quit_program() setup_debugger(debugger, TEST_FILE, (11, 13), test_continue_cb, cont=False)
def test_step_out(debugger): state = AsyncState() def test_step_out_cb(): if state.state == 0: state.inc() debugger.exec_step_out() else: location = debugger.file_manager.get_current_location() assert location[0] == make_location(11)[0] assert location[1] in (11, 12) debugger.quit_program() setup_debugger(debugger, TEST_FILE, 5, test_step_out_cb, cont=False)
def test_composite(debugger): def test_composite_cb(): strA = debugger.variable_manager.get_variable("strA") assert strA.type.type_category == TypeCategory.Struct children = strA.children assert children[0].name == "x" assert children[0].value == "5" assert children[1].name == "y" assert children[1].value == "hello" clsA = debugger.variable_manager.get_variable("clsA") assert clsA.type.type_category == TypeCategory.Class assert clsA.children[0].children[0].value == strA.children[0].value setup_debugger(debugger, TEST_FILE, TEST_LINE, test_composite_cb)
def test_thread_frame(debugger): def test_thread_frame_cb(): thread_info = debugger.thread_manager.get_thread_info() frame = debugger.thread_manager.get_current_frame(True) assert thread_info.selected_thread.frame.func == frame.func vars = [var.name for var in frame.variables] assert "thread" in vars assert "result" in vars select_other_thread(debugger) frame = debugger.thread_manager.get_current_frame(True) assert "param" in [var.name for var in frame.variables] debugger.quit_program() setup_debugger(debugger, TEST_FILE, TEST_LINE, test_thread_frame_cb, cont=False)
def test_disassemble(debugger): def test_disassemble_cb(): disas = debugger.file_manager.disassemble(SRC_FILE, 3) assert len(disas) == 6 decl_ds = disas[1] assert decl_ds["line"] == 3 assert len(decl_ds["instructions"]) == 1 assert decl_ds["instructions"][0] in (generate_instructions( "movl $0x5,-0x4(%{})", "ebp", "rbp")) assign_ds = disas[2] assert assign_ds["line"] == 4 assert len(assign_ds["instructions"]) == 1 assert assign_ds["instructions"][0] in (generate_instructions( "addl $0xa,-0x4(%{})", "ebp", "rbp")) setup_debugger(debugger, TEST_FILE, 3, test_disassemble_cb)
def test_disassemble(debugger): def test_disassemble_cb(): disas = debugger.file_manager.disassemble(SRC_FILE, 3) assert len(disas) == 6 decl_ds = disas[1] assert decl_ds["line"] == 3 assert len(decl_ds["instructions"]) == 1 assert decl_ds["instructions"][0] in ( generate_instructions("movl $0x5,-0x4(%{})", "ebp", "rbp")) assign_ds = disas[2] assert assign_ds["line"] == 4 assert len(assign_ds["instructions"]) == 1 assert assign_ds["instructions"][0] in ( generate_instructions("addl $0xa,-0x4(%{})", "ebp", "rbp")) setup_debugger(debugger, TEST_FILE, 3, test_disassemble_cb)
def test_startup_info(debugger): """ @type debugger: debugger.debugger_api.Debugger """ env_value = "test test_env" startup_info = StartupInfo("test1 test2", os.getcwd(), [("DEVI_ENV_TEST", env_value)]) def test_startup_info_cb(): lines = [] for x in xrange(5): lines.append(debugger.io_manager.stdout.readline()[:-1]) assert lines == [ "3", os.path.abspath("src/{}".format(TEST_FILE)), "test1", "test2", env_value ] setup_debugger(debugger, TEST_FILE, TEST_LINE, test_startup_info_cb, startup_info)
def test_update_variable(debugger): def test_update_variable_cb(): a = debugger.variable_manager.get_variable("a") a.value = "8" assert debugger.variable_manager.get_variable("a").value == "8" d = debugger.variable_manager.get_variable("d") d.value = "hi" assert debugger.variable_manager.get_variable("d").value == "hi" vec = debugger.variable_manager.get_variable("vec") vec.count = vec.max_size debugger.variable_manager.get_vector_items(vec) vec.children[0].value = "10" vec = debugger.variable_manager.get_variable("vec") vec.count = vec.max_size debugger.variable_manager.get_vector_items(vec) assert vec.children[0].value == "10" setup_debugger(debugger, TEST_FILE, TEST_LINE, test_update_variable_cb)
def test_frame_list(debugger): def test_frame_list_cb(): assert len(debugger.thread_manager.get_frames()) == 2 setup_debugger(debugger, TEST_FILE, TEST_LINE, test_frame_list_cb)
def test_address_invalid_line(debugger): def test_address_invalid_line_cb(): assert debugger.file_manager.get_line_address(SRC_FILE, 100) is None setup_debugger(debugger, TEST_FILE, 3, test_address_invalid_line_cb)
def test_address_no_code(debugger): def test_address_no_code_cb(): assert debugger.file_manager.get_line_address(SRC_FILE, 5) is None setup_debugger(debugger, TEST_FILE, 3, test_address_no_code_cb)
def test_stop(debugger): setup_debugger(debugger, TEST_FILE, [], None, cont=False, wait=False) time.sleep(0.5) debugger.quit_program()