Revert "[ARM32/Linux] Copy tests.zip only for CI test and use x86 unittest"
[platform/upstream/coreclr.git] / enablesanitizers.sh
1 #!/usr/bin/env bash
2
3 if [ $# -eq 0 ]; then
4     echo "Script for enabling CLang sanitizers for debug builds."
5     echo "*Only tested on Ubuntu x64."
6     echo "*This script must be 'sourced' (via dot+space) so that changes to environment variables are preserved. Run like this:"    
7     if [ "$(dirname $0)" = "." ]; then
8         echo " . enablesanitizers.sh [options]"
9     else
10         echo " cd $(dirname $0);. enablesanitizers.sh [options]; cd -"
11     fi
12     echo "Usage: [asan] [ubsan] [lsan] [all] [off] [clangx.y]"
13     echo " asan: optional argument to enable Address Sanitizer."
14     echo " ubsan: optional argument to enable Undefined Behavior Sanitizer."
15     echo " lsan - optional argument to enable memory Leak Sanitizer."
16     echo " all - optional argument to enable asan, ubsan and lsan."
17     echo " off - optional argument to turn off all sanitizers."
18     echo " clangx.y - optional argument to specify clang version x.y. which is used to resolve stack traces. Default is 3.6"
19 else
20     # default to clang 3.6 instead of 3.5 because it supports print_stacktrace (otherwise only one stack frame)
21     __ClangMajorVersion=3
22     __ClangMinorVersion=6
23
24     __EnableASan=0
25     __EnableUBSan=0
26     __EnableLSan=0
27     __TurnOff=0
28     __Options=
29
30     for i in "$@"
31         do
32             lowerI="$(echo $i | awk '{print tolower($0)}')"
33             case $lowerI in
34             asan)
35                 __EnableASan=1
36                 ;;
37             ubsan)
38                 __EnableUBSan=1
39                 ;;
40             lsan)
41                 __EnableASan=1
42                 __EnableLSan=1
43                 ;;
44             all)
45                 __EnableASan=1
46                 __EnableUBSan=1
47                 __EnableLSan=1
48                 ;;
49             off)
50                 __TurnOff=1
51                 ;;
52             clang3.5)
53                 __ClangMajorVersion=3
54                 __ClangMinorVersion=5
55                 ;;
56             clang3.6)
57                 __ClangMajorVersion=3
58                 __ClangMinorVersion=6
59                 ;;
60             clang3.7)
61                 __ClangMajorVersion=3
62                 __ClangMinorVersion=7
63                 ;;
64             *)
65                 echo "Unknown arg: $i"
66                 return 1
67         esac
68     done
69
70     if [ $__TurnOff == 1 ]; then
71         unset DEBUG_SANITIZERS
72         echo "Setting DEBUG_SANITIZERS="
73     else
74         # for now, specify alloc_dealloc_mismatch=0 as there are too many error reports that are not an issue
75         ASAN_OPTIONS="symbolize=1 alloc_dealloc_mismatch=0"
76         # when Clang 3.8 available, add: suppressions=$(readlink -f sanitizersuppressions.txt)
77         UBSAN_OPTIONS="print_stacktrace=1"
78
79         if [ $__EnableASan == 1 ]; then
80             __Options="$__Options asan"
81         fi
82         if [ $__EnableUBSan == 1 ]; then
83             __Options="$__Options ubsan"
84         fi
85         if [ $__EnableLSan == 1 ]; then
86             ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks"
87         fi
88
89         # passed to build.sh
90         DEBUG_SANITIZERS="$__Options"
91         export DEBUG_SANITIZERS
92         echo "Setting DEBUG_SANITIZERS=$DEBUG_SANITIZERS"
93
94         # used by ASan at run-time
95         ASAN_OPTIONS="\"$ASAN_OPTIONS\""
96         export ASAN_OPTIONS
97         echo "Setting ASAN_OPTIONS=$ASAN_OPTIONS"
98
99         UBSAN_OPTIONS="\"$UBSAN_OPTIONS\""
100         export UBSAN_OPTIONS
101         echo "Setting UBSAN_OPTIONS=$UBSAN_OPTIONS"
102
103         # used by ASan at run-time
104         ASAN_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer-$__ClangMajorVersion.$__ClangMinorVersion"
105         export ASAN_SYMBOLIZER_PATH
106         echo "Setting ASAN_SYMBOLIZER_PATH=$ASAN_SYMBOLIZER_PATH"
107         echo "Done. You can now run: build.sh Debug clang$__ClangMajorVersion.$__ClangMinorVersion"
108     fi
109
110     unset __ClangMajorVersion
111     unset __ClangMinorVersion
112     unset __EnableASan
113     unset __EnableUBSan
114     unset __EnableLSan
115     unset __TurnOff
116     unset __Options
117 fi