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