6
6
from lldbsuite .test .lldbtest import *
7
7
from lldbsuite .test import lldbutil
8
8
import lldbdap_testcase
9
+ import re
9
10
10
11
11
12
class TestDAP_threads (lldbdap_testcase .DAPTestCaseBase ):
12
- @skipIfWindows
13
13
def test_correct_thread (self ):
14
14
"""
15
15
Tests that the correct thread is selected if we continue from
@@ -19,7 +19,7 @@ def test_correct_thread(self):
19
19
"""
20
20
program = self .getBuildArtifact ("a.out" )
21
21
self .build_and_launch (program )
22
- source = "main.c "
22
+ source = "main.cpp "
23
23
breakpoint_line = line_number (source , "// break here" )
24
24
lines = [breakpoint_line ]
25
25
# Set breakpoint in the thread function
@@ -42,8 +42,10 @@ def test_correct_thread(self):
42
42
)
43
43
self .assertFalse (stopped_event [0 ]["body" ]["preserveFocusHint" ])
44
44
self .assertTrue (stopped_event [0 ]["body" ]["threadCausedFocus" ])
45
+ # All threads should be named Thread {index}
46
+ threads = self .dap_server .get_threads ()
47
+ self .assertTrue (all (re .match (r"^Thread \d+$" , t ["name" ]) for t in threads ))
45
48
46
- @skipIfWindows
47
49
def test_thread_format (self ):
48
50
"""
49
51
Tests the support for custom thread formats.
@@ -54,7 +56,7 @@ def test_thread_format(self):
54
56
customThreadFormat = "This is thread index #${thread.index}" ,
55
57
stopCommands = ["thread list" ],
56
58
)
57
- source = "main.c "
59
+ source = "main.cpp "
58
60
breakpoint_line = line_number (source , "// break here" )
59
61
lines = [breakpoint_line ]
60
62
# Set breakpoint in the thread function
@@ -63,8 +65,18 @@ def test_thread_format(self):
63
65
len (breakpoint_ids ), len (lines ), "expect correct number of breakpoints"
64
66
)
65
67
self .continue_to_breakpoints (breakpoint_ids )
66
- # We are stopped at the second thread
68
+ # We are stopped at the first thread
67
69
threads = self .dap_server .get_threads ()
68
70
print ("got thread" , threads )
69
- self .assertEqual (threads [0 ]["name" ], "This is thread index #1" )
70
- self .assertEqual (threads [1 ]["name" ], "This is thread index #2" )
71
+ if self .getPlatform () == "windows" :
72
+ # Windows creates a thread pool once WaitForSingleObject is called
73
+ # by thread.join(). As we are in the thread function, we can't be
74
+ # certain that join() has been called yet and a thread pool has
75
+ # been created, thus we only check for the first two threads.
76
+ names = list (sorted (t ["name" ] for t in threads ))[:2 ]
77
+ self .assertEqual (
78
+ names , ["This is thread index #1" , "This is thread index #2" ]
79
+ )
80
+ else :
81
+ self .assertEqual (threads [0 ]["name" ], "This is thread index #1" )
82
+ self .assertEqual (threads [1 ]["name" ], "This is thread index #2" )
0 commit comments