[lldb-dev] Testcase startup boiler-plate...

Jim Ingham via lldb-dev lldb-dev at lists.llvm.org
Fri Feb 2 11:21:35 PST 2018


I've seen a couple new testcases coming past that copy the standard:

        exe = self.getBuildArtifact("a.out")

        self.target = self.dbg.CreateTarget(exe)
        self.assertTrue(self.target, VALID_TARGET)

        main_bp = self.target.BreakpointCreateByName("main")
        self.assertTrue(main_bp, VALID_BREAKPOINT)

        self.process = self.target.LaunchSimple(
            None, None, self.get_process_working_directory())
        self.assertTrue(self.process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        self.assertTrue(self.process.GetState() == lldb.eStateStopped,
                        STOPPED_DUE_TO_BREAKPOINT)

etc. to make a target, set a breakpoint by name (or source regex), run the target, and make sure it hits the breakpoint.  That's really my fault, I should have provided a better way to do that a long time ago - apologies - but now you should be able to do all that with:

       (target, process, thread, breakpoint) = lldbutil.run_to_name_breakpoint(self, "main")

or the equivalent "run_to_source_breakpoint".  I bet a good percentage of the text in the testsuite is this repetitive pattern.  Simplifying it would for instance have made Adrian's task of building out of tree much less tedious...

It would be great if folks writing new tests would use this form instead, and if you're touching a test and have itchy fingers (or generally find time hanging heavy on your hands) by all means convert tests to this form!

If there's anything else that needs to get added to make these functions broadly useable, please ping me and I'll add it.

For reference, there's a sample test in:

   packages/Python/lldbsuite/test/sample_test/TestSampleTest.py

that does it this way and is a better starting point for new tests.

Thanks!

Jim


More information about the lldb-dev mailing list