• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/sh
2
3touch REPORT
4rm REPORT
5chmod +x sanitize/asan/*
6
7num_s=0
8num_f=0
9num_skip=0
10
11function skip {
12    echo skip
13    let num_skip=$num_skip+1
14}
15
16
17for case in `ls sanitize/asan`
18do
19    echo [Runing test] : sanitize/asan/$case
20    if [ "$case" = "use-after-return" ]; then
21        ASAN_OPTIONS=detect_stack_use_after_return=1 sanitize/asan/$case 2>tmp
22    elif [ "$case" = "IO-a" ] | [ "$case" = "IO-b" ]; then
23        ASAN_OPTIONS=check_initialization_order=true sanitize/asan/$case 2>tmp
24    else
25        ASAN_OPTIONS='' sanitize/asan/$case 2>tmp
26    fi
27
28    # check result
29    if [ "$case" = "memory-leaks" ];then
30        grep -nr 'SUMMARY: ' tmp | grep "leaked in"
31    else
32        grep -nr 'SUMMARY: ' tmp | grep $case
33    fi
34    res=$?
35
36    # Specially
37    if [ res -ne 0 ] && [ "$case" = "IO-b" ];then
38        echo "$case succeeded."
39        let num_s=$num_s+1
40    elif [ res -ne 0 ];then
41        echo "[ERROR] asan/$case failed." | tee -a REPORT
42        sanitize/asan/$case >> REPORT
43        let num_f=$num_f+1
44    else
45        echo "$case succeeded."
46        let num_s=$num_s+1
47    fi
48done
49
50for case in `ls sanitize/scudo`
51do
52    cat /dev/null > tmp
53    echo [Runing test] : sanitize/scudo/$case
54    if [ "$case" = "aligned-new" ];then
55        sanitize/scudo/$case valid 2>tmp
56        r1=$?
57        SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case invalid 2>tmp
58        r2=$?
59        SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case invalid 2>tmp #not
60        grep -nr 'Scudo ERROR: ' tmp >/dev/null
61        r3=$?
62        let res=$r1+$r2+$r3
63        res2=$r1+$r2+$r3
64    elif [ "$case" = "alignment" ];then
65        sanitize/scudo/$case pointers 2>tmp #not
66        grep -nr 'Scudo ERROR: ' tmp >/dev/null
67        res=$?
68    elif [ "$case" = "dealloc-race" ];then
69        SCUDO_OPTIONS="QuarantineChunksUpToSize=0" sanitize/scudo/$case 2>tmp
70        res=$?
71    elif [ "$case" = "double-free" ];then
72        sanitize/scudo/$case malloc 2>tmp
73        grep -nr "ERROR: invalid chunk state" tmp >/dev/null
74        r1=$?
75        sanitize/scudo/$case new 2>tmp
76        grep -nr "ERROR: invalid chunk state" tmp >/dev/null
77        r2=$?
78        sanitize/scudo/$case newarray 2>tmp
79        grep -nr "ERROR: invalid chunk state" tmp >/dev/null
80        r3=$?
81        let res=$r1+$r2+$r3
82        res2=$r1+$r2+$r3
83    elif [ "$case" = "fsanitize" ];then
84        skip #build error
85        continue
86    elif [ "$case" = "interface" ];then
87        sanitize/scudo/$case ownership 2>tmp
88        r1=$?
89        sanitize/scudo/$case ownership-and-size 2>tmp
90        r2=$?
91        sanitize/scudo/$case heap-size 2>tmp
92        r3=$?
93        SCUDO_OPTIONS="allocator_may_return_null=1" sanitize/scudo/$case soft-limit 2>tmp
94        r4=$?
95        SCUDO_OPTIONS="allocator_may_return_null=1" sanitize/scudo/$case hard-limit 2>tmp
96        grep -nr 'Scudo ERROR: ' tmp >/dev/null
97        r5=$?
98        let res=$r1+$r2+$r3+$r4+$r5
99        res2=$r1+$r2+$r3+$r4+$r5
100    elif [ "$case" = "memalign" ];then
101        skip
102        continue
103        # sanitize/scudo/$case valid 2>tmp
104        # sanitize/scudo/$case invalid 2>tmp
105        # scudo_opts=allocator_may_return_null=1 sanitize/scudo/$case invalid 2>tmp
106        # sanitize/scudo/$case double-free 2>tmp
107        # scudo_opts=DeallocationTypeMismatch=1  sanitize/scudo/$case realloc 2>tmp
108        # scudo_opts=DeallocationTypeMismatch=0  sanitize/scudo/$case realloc 2>tmp
109    elif [ "$case" = "mismatch" ];then
110        SCUDO_OPTIONS=DeallocationTypeMismatch=1 sanitize/scudo/$case mallocdel 2>tmp #not
111        grep -nr 'Scudo ERROR: ' tmp >/dev/null
112        r1=$?
113        SCUDO_OPTIONS=DeallocationTypeMismatch=0 sanitize/scudo/$case mallocdel 2>tmp
114        r2=$?
115        SCUDO_OPTIONS=DeallocationTypeMismatch=1 sanitize/scudo/$case newfree   2>tmp #not
116        grep -nr 'Scudo ERROR: ' tmp >/dev/null
117        r3=$?
118        SCUDO_OPTIONS=DeallocationTypeMismatch=0 sanitize/scudo/$case newfree   2>tmp
119        r4=$?
120        let res=$r1+$r2+$r3+$r4
121        res2=$r1+$r2+$r3+$r4
122    elif [ "$case" = "preinit" ];then
123        skip # UNSUPPORTED
124        continue
125    elif [ "$case" = "options" ];then
126        sanitize/scudo/$case 2>tmp
127        r1=$?
128        SCUDO_OPTIONS=DeallocationTypeMismatch=0 sanitize/scudo/$case 2>tmp
129        r2=$?
130        SCUDO_OPTIONS=DeallocationTypeMismatch=1 sanitize/scudo/$case 2>tmp #not
131        grep -nr 'Scudo ERROR: ' tmp >/dev/null
132        r3=$?
133        let res=$r1+$r2+$r3
134        res2=$r1+$r2+$r3
135    elif [ "$case" = "preload" ];then
136        skip
137        continue
138        # env LD_PRELOAD=%shared_libscudo    not %run %t 2>tmp | FileCheck %s
139        # env LD_PRELOAD=%shared_minlibscudo not %run %t 2>tmp | FileCheck %s
140    elif [ "$case" = "realloc" ];then
141        skip
142        continue
143        # sanitize/scudo/$case pointers   2>tmp
144        # sanitize/scudo/$case contents   2>tmp
145        # sanitize/scudo/$case usablesize 2>tmp
146    elif [ "$case" = "rss" ];then
147        sanitize/scudo/$case 2>tmp
148        r1=$?
149        SCUDO_OPTIONS="soft_rss_limit_mb=128" sanitize/scudo/$case 2>tmp
150        r2=$?
151        SCUDO_OPTIONS="hard_rss_limit_mb=128" sanitize/scudo/$case 2>tmp
152        r3=$?
153        SCUDO_OPTIONS="soft_rss_limit_mb=32:allocator_may_return_null=0" sanitize/scudo/$case 2>tmp
154        grep -nr 'Scudo ERROR: ' tmp >/dev/null
155        r4=$? #not
156        SCUDO_OPTIONS="soft_rss_limit_mb=32:allocator_may_return_null=1" sanitize/scudo/$case 2>tmp
157        r5=$?
158        SCUDO_OPTIONS="soft_rss_limit_mb=32:allocator_may_return_null=0:can_use_proc_maps_statm=0" sanitize/scudo/$case 2>tmp
159        grep -nr 'Scudo ERROR: ' tmp >/dev/null
160        r6=$? #not
161        SCUDO_OPTIONS="soft_rss_limit_mb=32:allocator_may_return_null=1:can_use_proc_maps_statm=0" sanitize/scudo/$case 2>tmp
162        r7=$?
163        SCUDO_OPTIONS="hard_rss_limit_mb=32:allocator_may_return_null=0" sanitize/scudo/$case 2>tmp
164        grep -nr 'Scudo ERROR: ' tmp >/dev/null
165        r8=$? #not
166        SCUDO_OPTIONS="hard_rss_limit_mb=32:allocator_may_return_null=1" sanitize/scudo/$case 2>tmp
167        grep -nr 'Scudo ERROR: ' tmp >/dev/null
168        r9=$? #not
169        SCUDO_OPTIONS="hard_rss_limit_mb=32:allocator_may_return_null=0:can_use_proc_maps_statm=0" sanitize/scudo/$case 2>tmp
170        grep -nr 'Scudo ERROR: ' tmp >/dev/null
171        r10=$? #not
172        SCUDO_OPTIONS="hard_rss_limit_mb=32:allocator_may_return_null=1:can_use_proc_maps_statm=0" sanitize/scudo/$case 2>tmp
173        grep -nr 'Scudo ERROR: ' tmp >/dev/null
174        r11=$? #not
175        let res=$r1+$r2+$r3+$r4+$r5+$r6+$r7+$r8+$r9+$r10+$r11
176        res2=$r1+$r2+$r3+$r4+$r5+$r6+$r7+$r8+$r9+$r10+$r11
177    elif [ "$case" = "sized-delete" ];then
178        SCUDO_OPTIONS=DeleteSizeMismatch=1 sanitize/scudo/$case gooddel    2>tmp
179        r1=$?
180        SCUDO_OPTIONS=DeleteSizeMismatch=1 sanitize/scudo/$case baddel     2>tmp  #not
181        grep -nr 'Scudo ERROR: ' tmp >/dev/null
182        r2=$?
183        SCUDO_OPTIONS=DeleteSizeMismatch=0 sanitize/scudo/$case baddel     2>tmp
184        r3=$?
185        SCUDO_OPTIONS=DeleteSizeMismatch=1 sanitize/scudo/$case gooddelarr 2>tmp
186        r4=$?
187        SCUDO_OPTIONS=DeleteSizeMismatch=1 sanitize/scudo/$case baddelarr  2>tmp  #not
188        grep -nr 'Scudo ERROR: ' tmp >/dev/null
189        r5=$?
190        SCUDO_OPTIONS=DeleteSizeMismatch=0 sanitize/scudo/$case baddelarr  2>tmp
191        r6=$?
192        let res=$r1+$r2+$r3+$r4+$r5+$r6
193        res2=$r1+$r2+$r3+$r4+$r5+$r6
194    elif [ "$case" = "sizes" ];then
195        SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case malloc 2>tmp #not
196        grep -nr 'Scudo ERROR: ' tmp >/dev/null
197        r1=$?
198        SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case malloc 2>tmp
199        r2=$?
200        SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case calloc 2>tmp #not
201        grep -nr 'Scudo ERROR: ' tmp >/dev/null
202        r3=$?
203        SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case calloc 2>tmp
204        r4=$?
205        SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case new 2>tmp #not
206        grep -nr 'Scudo ERROR: ' tmp >/dev/null
207        r5=$?
208        SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case new 2>tmp #not
209        grep -nr 'Scudo ERROR: ' tmp >/dev/null
210        r6=$?
211        SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case new-nothrow 2>tmp #not
212        grep -nr 'Scudo ERROR: ' tmp >/dev/null
213        r7=$?
214        SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case new-nothrow 2>tmp
215        r8=$?
216        sanitize/scudo/$case usable 2>tmp
217        r9=$?
218        let res=$r1+$r2+$r3+$r4+$r5+$r6+$r7+$r8+$r9
219        res2=$r1+$r2+$r3+$r4+$r5+$r6+$r7+$r8+$r9
220    else
221        sanitize/scudo/$case 2>tmp
222        grep -nr 'Scudo ERROR: ' tmp >/dev/null
223        res=$?
224    fi
225
226    if [ res -ne 0 ];then
227        # echo res
228        echo "[ERROR] scudo/$case failed." | tee -a REPORT
229        let num_f=$num_f+1
230        continue
231    else
232        echo "scudo/$case succeeded."
233        let num_s=$num_s+1
234        continue
235    fi
236    echo
237done
238
239for case in `ls sanitize/ubsan`
240do
241    echo [Runing test] : sanitize/ubsan/$case
242    sanitize/ubsan/$case 2>tmp
243    # check result
244    grep -nr 'SUMMARY: UndefinedBehaviorSanitizer' tmp
245    res=$?
246    if [ res -ne 0 ];then
247        echo "[ERROR] ubsan/$case failed." | tee -a REPORT
248        sanitize/ubsan/$case >> REPORT
249        let num_f=$num_f+1
250    else
251        echo "ubsan/$case succeeded."
252        let num_s=$num_s+1
253    fi
254done
255
256let sum_case=$num_s+$num_f+$num_skip
257echo "All:$sum_case Succeeded:$num_s   Failed:$num_f    Skiped:$num_skip"
258if [ $num_f -eq 0 ];then
259    echo "No test failed, report not create."
260fi
261rm tmp
262