16
16
import lldbsuite .test .decorators as decorators
17
17
import lldbsuite .test .lldbtest as lldbtest
18
18
import lldbsuite .test .lldbutil as lldbutil
19
+ from lldbsuite .test_event .build_exception import BuildError
19
20
import os
20
21
import unittest2
21
22
import json
@@ -29,8 +30,16 @@ class AsanSwiftTestCase(lldbtest.TestBase):
29
30
@decorators .skipIfLinux
30
31
@decorators .skipUnlessSwiftAddressSanitizer
31
32
def test_asan_swift (self ):
32
- self .build ()
33
- self .do_test ()
33
+ self .build (make_targets = ["asan" ])
34
+ self .do_test_asan ()
35
+
36
+ @decorators .skipIf (oslist = decorators .no_match (["macosx" ]))
37
+ def test_libsanitizers_swift (self ):
38
+ try :
39
+ self .build (make_targets = ["libsanitizers" ])
40
+ except BuildError as e :
41
+ self .skipTest ("failed to build with libsanitizers" )
42
+ self .do_test_libsanitizers ()
34
43
35
44
def setUp (self ):
36
45
lldbtest .TestBase .setUp (self )
@@ -39,7 +48,7 @@ def setUp(self):
39
48
self .line_breakpoint = lldbtest .line_number (
40
49
self .main_source , '// breakpoint' )
41
50
42
- def do_test (self ):
51
+ def do_test_asan (self ):
43
52
exe_name = "a.out"
44
53
exe = self .getBuildArtifact (exe_name )
45
54
@@ -101,3 +110,33 @@ def do_test(self):
101
110
substrs = [
102
111
'Memory allocated by Thread 1' ,
103
112
'main.swift' ])
113
+
114
+ # Test line numbers: rdar://126237493
115
+ def do_test_libsanitizers (self ):
116
+ exe_name = "a.out"
117
+ exe = self .getBuildArtifact (exe_name )
118
+
119
+ # Create the target
120
+ target = self .dbg .CreateTarget (exe )
121
+ self .assertTrue (target , lldbtest .VALID_TARGET )
122
+
123
+ self .runCmd ("env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0" )
124
+
125
+ self .runCmd ("run" )
126
+
127
+ # the stop reason of the thread should be a ASan report.
128
+ self .expect ("thread list" , "Heap buffer overflow" , substrs = [
129
+ 'stopped' , 'stop reason = Heap buffer overflow' ])
130
+
131
+ process = self .dbg .GetSelectedTarget ().process
132
+ thread = process .GetSelectedThread ()
133
+
134
+ self .assertEqual (
135
+ thread .GetStopReason (),
136
+ lldb .eStopReasonInstrumentation )
137
+
138
+ self .expect (
139
+ "memory history `__asan_get_report_address()`" ,
140
+ substrs = [
141
+ 'Memory allocated by Thread 1' ,
142
+ 'main.swift' ])
0 commit comments