brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · cd60227 Raw
148 lines · python
1"""2Test lldb data formatter subsystem.3"""4 5import lldb6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9 10 11class NSDictionarySyntheticTestCase(TestBase):12    def setUp(self):13        # Call super's setUp().14        TestBase.setUp(self)15        # Find the line number to break at.16        self.line = line_number("main.m", "// Set break point at this line.")17 18    @skipUnlessDarwin19    def test_rdar11988289_with_run_command(self):20        """Test that NSDictionary reports its synthetic children properly."""21        self.build()22        self.run_tests()23 24    @skipUnlessDarwin25    def test_rdar11988289_with_run_command_no_const(self):26        """Test that NSDictionary reports its synthetic children properly."""27        disable_constant_classes = {28            "CFLAGS_EXTRAS": "-fno-constant-nsnumber-literals "29            + "-fno-constant-nsarray-literals "30            + "-fno-constant-nsdictionary-literals",31        }32        # FIXME: Remove when flags are available upstream.33        self.build(dictionary=disable_constant_classes, compiler="xcrun clang")34        self.run_tests()35 36    def run_tests(self):37        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)38 39        lldbutil.run_break_set_by_file_and_line(40            self, "main.m", self.line, num_expected_locations=1, loc_exact=True41        )42 43        self.runCmd("run", RUN_SUCCEEDED)44 45        # The stop reason of the thread should be breakpoint.46        self.expect(47            "thread list",48            STOPPED_DUE_TO_BREAKPOINT,49            substrs=["stopped", "stop reason = breakpoint"],50        )51 52        # This is the function to remove the custom formats in order to have a53        # clean slate for the next test case.54        def cleanup():55            self.runCmd("type format clear", check=False)56            self.runCmd("type summary clear", check=False)57            self.runCmd("type synth clear", check=False)58 59        # Execute the cleanup function during test case tear down.60        self.addTearDownHook(cleanup)61 62        # Now check that we are displaying Cocoa classes correctly63        self.expect("frame variable dictionary", substrs=["3 key/value pairs"])64        self.expect("frame variable mutabledict", substrs=["4 key/value pairs"])65        self.expect(66            "frame variable dictionary --ptr-depth 1",67            substrs=[68                "3 key/value pairs",69                "[0] = ",70                "key = 0x",71                "value = 0x",72                "[1] = ",73                "[2] = ",74            ],75        )76        self.expect(77            "frame variable mutabledict --ptr-depth 1",78            substrs=[79                "4 key/value pairs",80                "[0] = ",81                "key = 0x",82                "value = 0x",83                "[1] = ",84                "[2] = ",85                "[3] = ",86            ],87        )88        self.expect(89            "frame variable dictionary --ptr-depth 1",90            substrs=[91                "3 key/value pairs",92                '@"bar"',93                '@"2 elements"',94                '@"baz"',95                "2 key/value pairs",96            ],97        )98        self.expect(99            "frame variable mutabledict --ptr-depth 1",100            substrs=[101                "4 key/value pairs",102                "(int)23",103                '@"123"',104                '@"http://www.apple.com"',105                '@"sourceofstuff"',106                "3 key/value pairs",107            ],108        )109        self.expect(110            "frame variable mutabledict --ptr-depth 2",111            substrs=[112                "4 key/value pairs",113                "(int)23",114                '@"123"',115                '@"http://www.apple.com"',116                '@"sourceofstuff"',117                "3 key/value pairs",118                '@"bar"',119                '@"2 elements"',120            ],121        )122 123        self.runCmd("settings set target.max-children-depth 6")124        self.expect(125            "frame variable mutabledict --ptr-depth 3",126            substrs=[127                "4 key/value pairs",128                "(int)23",129                '@"123"',130                '@"http://www.apple.com"',131                '@"sourceofstuff"',132                "3 key/value pairs",133                '@"bar"',134                '@"2 elements"',135                "(int)1",136                '@"two"',137            ],138        )139 140        self.assertTrue(141            self.frame().FindVariable("dictionary").MightHaveChildren(),142            "dictionary says it does not have children!",143        )144        self.assertTrue(145            self.frame().FindVariable("mutabledict").MightHaveChildren(),146            "mutable says it does not have children!",147        )148