brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · d288f0d Raw
96 lines · python
1import os2 3import dap_server4import lldbdap_testcase5from lldbsuite.test import lldbutil6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8 9 10class TestDAP_variables_children(lldbdap_testcase.DAPTestCaseBase):11    def test_get_num_children(self):12        """Test that GetNumChildren is not called for formatters not producing indexed children."""13        program = self.getBuildArtifact("a.out")14        self.build_and_launch(15            program,16            preRunCommands=[17                "command script import '%s'" % self.getSourcePath("formatter.py")18            ],19        )20        source = "main.cpp"21        breakpoint_ids = self.set_source_breakpoints(22            source, [line_number(source, "// break here")]23        )24        self.continue_to_breakpoints(breakpoint_ids)25 26        local_vars = self.dap_server.get_local_variables()27        print(local_vars)28        indexed = next(filter(lambda x: x["name"] == "indexed", local_vars))29        not_indexed = next(filter(lambda x: x["name"] == "not_indexed", local_vars))30        self.assertIn("indexedVariables", indexed)31        self.assertEqual(indexed["indexedVariables"], 1)32        self.assertNotIn("indexedVariables", not_indexed)33 34        self.assertIn(35            "['Indexed']",36            self.dap_server.request_evaluate(37                "`script formatter.num_children_calls", context="repl"38            )["body"]["result"],39        )40 41    @skipIf(archs=["arm$", "arm64", "aarch64"])42    def test_return_variable_with_children(self):43        """44        Test the stepping out of a function with return value show the children correctly45        """46        program = self.getBuildArtifact("a.out")47        self.build_and_launch(program)48 49        function_name = "test_return_variable_with_children"50        breakpoint_ids = self.set_function_breakpoints([function_name])51 52        self.assertEqual(len(breakpoint_ids), 1)53        self.continue_to_breakpoints(breakpoint_ids)54 55        threads = self.dap_server.get_threads()56        for thread in threads:57            if thread.get("reason") == "breakpoint":58                thread_id = thread.get("id")59                self.assertIsNot(thread_id, None)60 61                self.stepOut(threadId=thread_id)62 63                local_variables = self.dap_server.get_local_variables()64 65                # verify has return variable as local66                result_variable = list(67                    filter(68                        lambda val: val.get("name") == "(Return Value)", local_variables69                    )70                )71                self.assertEqual(len(result_variable), 1)72                result_variable = result_variable[0]73 74                result_var_ref = result_variable.get("variablesReference")75                self.assertIsNot(result_var_ref, None, "There is no result value")76 77                result_value = self.dap_server.request_variables(result_var_ref)78                result_children = result_value["body"]["variables"]79                self.assertNotEqual(80                    result_children, None, "The result does not have children"81                )82 83                verify_children = {"buffer": '"hello world!"', "x": "10", "y": "20"}84                for child in result_children:85                    actual_name = child["name"]86                    actual_value = child["value"]87                    verify_value = verify_children.get(actual_name)88                    self.assertNotEqual(verify_value, None)89                    self.assertEqual(90                        actual_value,91                        verify_value,92                        "Expected child value does not match",93                    )94 95                break96