@@ -28,7 +28,7 @@ class TsanSwiftAccessRaceTestCase(lldbtest.TestBase):
2828 @swiftTest
2929 @skipIfLinux
3030 @skipUnlessSwiftThreadSanitizer
31- @skipIfAsan # This test does not behave reliable with an ASANified LLDB.
31+ @skipIfAsan # This test does not behave reliable with an ASANified LLDB.
3232 def test_tsan_swift (self ):
3333 self .build ()
3434 self .do_test ()
@@ -50,9 +50,15 @@ def do_test(self):
5050 for m in target .module_iter ():
5151 libspec = m .GetFileSpec ()
5252 if "clang_rt" in libspec .GetFilename ():
53- runtimes .append (os .path .join (libspec .GetDirectory (), libspec .GetFilename ()))
53+ runtimes .append (
54+ os .path .join (libspec .GetDirectory (), libspec .GetFilename ())
55+ )
5456 self .registerSharedLibrariesWithTarget (target , runtimes )
5557
58+ # Enable verbose logging to help diagnose rdar://153220781
59+ self .runCmd ("log enable lldb break platform process target thread" )
60+ self .addTearDownHook (lambda : self .runCmd ("log disable gdb-remote packets" ))
61+
5662 # Unfortunately the runtime itself isn't 100% reliable in reporting TSAN errors.
5763 failure_reasons = []
5864 stop_reason = None
@@ -62,36 +68,47 @@ def do_test(self):
6268 info .SetWorkingDirectory (self .get_process_working_directory ())
6369 process = target .Launch (info , error )
6470 if not error .success :
65- failure_reasons .append (f"Failed to bring up process, error: { error .value } " )
71+ failure_reasons .append (
72+ f"Failed to bring up process, error: { error .value } "
73+ )
6674 continue
6775
6876 stop_reason = process .GetSelectedThread ().GetStopReason ()
6977 if stop_reason == lldb .eStopReasonInstrumentation :
7078 break
71- failure_reasons .append (f"Invalid stop_reason: { stop_reason } " )
79+
80+ thread = process .GetSelectedThread ()
81+ stop_reason_data = [
82+ thread .GetStopReasonDataAtIndex (index )
83+ for index in range (thread .GetStopReasonDataCount ())
84+ ]
85+ failure_reasons .append (
86+ f"Invalid stop_reason: { stop_reason } , stop_reason_data: { stop_reason_data } "
87+ )
7288
7389 self .assertEqual (
74- stop_reason ,
90+ stop_reason ,
7591 lldb .eStopReasonInstrumentation ,
76- f"Failed with { len (failure_reasons )} attempts with reasons: { failure_reasons } " )
77-
92+ f"Failed with { len (failure_reasons )} attempts with reasons: { failure_reasons } " ,
93+ )
94+
7895 # the stop reason of the thread should be a TSan report.
79- self .expect ("thread list" , "A Swift access race should be detected" ,
80- substrs = ['stopped' , 'stop reason = Swift access race detected' ])
96+ self .expect (
97+ "thread list" ,
98+ "A Swift access race should be detected" ,
99+ substrs = ["stopped" , "stop reason = Swift access race detected" ],
100+ )
81101
82102 self .expect (
83103 "thread info -s" ,
84104 "The extended stop info should contain the TSan provided fields" ,
85- substrs = [
86- "instrumentation_class" ,
87- "description" ,
88- "mops" ])
105+ substrs = ["instrumentation_class" , "description" , "mops" ],
106+ )
89107
90- output_lines = self .res .GetOutput ().split (' \n ' )
91- json_line = ' \n ' .join (output_lines [2 :])
108+ output_lines = self .res .GetOutput ().split (" \n " )
109+ json_line = " \n " .join (output_lines [2 :])
92110 data = json .loads (json_line )
93111 self .assertEqual (data ["instrumentation_class" ], "ThreadSanitizer" )
94112 self .assertEqual (data ["issue_type" ], "external-race" )
95113 self .assertEqual (len (data ["mops" ]), 2 )
96114 self .assertTrue (data ["location_filename" ].endswith ("/main.swift" ))
97-
0 commit comments