]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/thread/break_after_join/TestBreakAfterJoin.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / thread / break_after_join / TestBreakAfterJoin.py
1 """
2 Test number of threads.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
13
14 class BreakpointAfterJoinTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # Find the line number for our breakpoint.
22         self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
23
24     @expectedFailureDarwin("llvm.org/pr15824") # thread states not properly maintained
25     @expectedFailureFreeBSD("llvm.org/pr18190") # thread states not properly maintained
26     @expectedFailureLinux("llvm.org/pr15824") # thread states not properly maintained
27     def test(self):
28         """Test breakpoint handling after a thread join."""
29         self.build(dictionary=self.getBuildFlags())
30
31         exe = os.path.join(os.getcwd(), "a.out")
32         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
33
34         # This should create a breakpoint in the main thread.
35         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.breakpoint, num_expected_locations=1)
36
37         # The breakpoint list should show 1 location.
38         self.expect("breakpoint list -f", "Breakpoint location shown correctly",
39             substrs = ["1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % self.breakpoint])
40
41         # Run the program.
42         self.runCmd("run", RUN_SUCCEEDED)
43
44         # The stop reason of the thread should be breakpoint.
45         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
46             substrs = ['stopped',
47                        'stop reason = breakpoint'])
48
49         # Get the target process
50         target = self.dbg.GetSelectedTarget()
51         process = target.GetProcess()
52
53         # The exit probably occurred during breakpoint handling, but it isn't
54         # guaranteed.  The main thing we're testing here is that the debugger
55         # handles this cleanly is some way.
56
57         # Get the number of threads
58         num_threads = process.GetNumThreads()
59
60         # Make sure we see at least six threads
61         self.assertTrue(num_threads >= 6, 'Number of expected threads and actual threads do not match.')
62
63         # Make sure all threads are stopped
64         for i in range(0, num_threads):
65             self.assertTrue(process.GetThreadAtIndex(i).IsStopped(),
66                             "Thread {0} didn't stop during breakpoint.".format(i))
67
68         # Run to completion
69         self.runCmd("continue")
70
71         # If the process hasn't exited, collect some information
72         if process.GetState() != lldb.eStateExited:
73             self.runCmd("thread list")
74             self.runCmd("process status")
75
76         # At this point, the inferior process should have exited.
77         self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)