@@ -15,75 +15,112 @@ if test -x "$(type -p clang)"; then
15
15
fi
16
16
export CC
17
17
18
+ msan=yes
19
+
18
20
TMPDIR=${TMPDIR:-/ tmp}
19
21
echo > ${TMPDIR} /testsanitizers$$ .c
20
22
if $CC -fsanitize=memory -c ${TMPDIR} /testsanitizers$$ .c -o ${TMPDIR} /testsanitizers$$ .o 2>&1 | grep " unrecognized" >& /dev/null; then
21
- echo " skipping msan test: -fsanitize=memory not supported"
22
- rm -f ${TMPDIR} /testsanitizers$$ .*
23
- exit 0
23
+ echo " skipping msan tests: -fsanitize=memory not supported"
24
+ msan=no
24
25
fi
25
26
rm -f ${TMPDIR} /testsanitizers$$ .*
26
27
27
28
# The memory sanitizer in versions of clang before 3.6 don't work with Go.
28
- if $CC --version | grep clang >& /dev/null; then
29
+ if test " $msan " = " yes " && $CC --version | grep clang >& /dev/null; then
29
30
ver=$( $CC --version | sed -e ' s/.* version \([0-9.-]*\).*/\1/' )
30
31
major=$( echo $ver | sed -e ' s/\([0-9]*\).*/\1/' )
31
32
minor=$( echo $ver | sed -e ' s/[0-9]*\.\([0-9]*\).*/\1/' )
32
33
if test " $major " -lt 3 || test " $major " -eq 3 -a " $minor " -lt 6; then
33
- echo " skipping msan test; clang version $major .$minor (older than 3.6)"
34
- exit 0
34
+ echo " skipping msan tests: clang version $major .$minor (older than 3.6)"
35
+ msan=no
35
36
fi
36
37
37
38
# Clang before 3.8 does not work with Linux at or after 4.1.
38
39
# golang.org/issue/12898.
39
- if test " $major " -lt 3 || test " $major " -eq 3 -a " $minor " -lt 8; then
40
+ if test " $msan " = " yes " -a " $ major" -lt 3 || test " $major " -eq 3 -a " $minor " -lt 8; then
40
41
if test " $( uname) " = Linux; then
41
42
linuxver=$( uname -r)
42
43
linuxmajor=$( echo $linuxver | sed -e ' s/\([0-9]*\).*/\1/' )
43
44
linuxminor=$( echo $linuxver | sed -e ' s/[0-9]*\.\([0-9]*\).*/\1/' )
44
45
if test " $linuxmajor " -gt 4 || test " $linuxmajor " -eq 4 -a " $linuxminor " -ge 1; then
45
- echo " skipping msan test; clang version $major .$minor (older than 3.8) incompatible with linux version $linuxmajor .$linuxminor (4.1 or newer)"
46
- exit 0
46
+ echo " skipping msan tests: clang version $major .$minor (older than 3.8) incompatible with linux version $linuxmajor .$linuxminor (4.1 or newer)"
47
+ msan=no
47
48
fi
48
49
fi
49
50
fi
50
51
fi
51
52
52
53
status=0
53
54
54
- if ! go build -msan std; then
55
- echo " FAIL: build -msan std"
56
- status=1
57
- fi
55
+ if test " $msan " = " yes" ; then
56
+ if ! go build -msan std; then
57
+ echo " FAIL: build -msan std"
58
+ status=1
59
+ fi
58
60
59
- if ! go run -msan msan.go; then
60
- echo " FAIL: msan"
61
- status=1
62
- fi
61
+ if ! go run -msan msan.go; then
62
+ echo " FAIL: msan"
63
+ status=1
64
+ fi
63
65
64
- if ! CGO_LDFLAGS=" -fsanitize=memory" CGO_CPPFLAGS=" -fsanitize=memory" go run -msan -a msan2.go; then
65
- echo " FAIL: msan2 with -fsanitize=memory"
66
- status=1
67
- fi
66
+ if ! CGO_LDFLAGS=" -fsanitize=memory" CGO_CPPFLAGS=" -fsanitize=memory" go run -msan -a msan2.go; then
67
+ echo " FAIL: msan2 with -fsanitize=memory"
68
+ status=1
69
+ fi
68
70
69
- if ! go run -msan -a msan2.go; then
70
- echo " FAIL: msan2"
71
- status=1
72
- fi
71
+ if ! go run -msan -a msan2.go; then
72
+ echo " FAIL: msan2"
73
+ status=1
74
+ fi
73
75
74
- if ! go run -msan msan3.go; then
75
- echo " FAIL: msan3"
76
- status=1
76
+ if ! go run -msan msan3.go; then
77
+ echo " FAIL: msan3"
78
+ status=1
79
+ fi
80
+
81
+ if ! go run -msan msan4.go; then
82
+ echo " FAIL: msan4"
83
+ status=1
84
+ fi
85
+
86
+ if go run -msan msan_fail.go 2> /dev/null; then
87
+ echo " FAIL: msan_fail"
88
+ status=1
89
+ fi
77
90
fi
78
91
79
- if ! go run -msan msan4.go; then
80
- echo " FAIL: msan4"
81
- status=1
92
+ tsan=yes
93
+
94
+ TMPDIR=${TMPDIR:-/ tmp}
95
+ echo > ${TMPDIR} /testsanitizers$$ .c
96
+ if $CC -fsanitize=thread -c ${TMPDIR} /testsanitizers$$ .c -o ${TMPDIR} /testsanitizers$$ .o 2>&1 | grep " unrecognized" >& /dev/null; then
97
+ echo " skipping tsan tests: -fsanitize=thread not supported"
98
+ tsan=no
82
99
fi
100
+ rm -f ${TMPDIR} /testsanitizers$$ .*
101
+
102
+ if test " $tsan " = " yes" ; then
103
+ err=${TMPDIR} /tsanerr$$ .out
104
+
105
+ if ! go run tsan.go 2> $err ; then
106
+ echo " FAIL: tsan"
107
+ status=1
108
+ elif grep -i warning $err > /dev/null 2>&1 ; then
109
+ cat $err
110
+ echo " FAIL: tsan"
111
+ status=1
112
+ fi
113
+
114
+ if ! go run tsan2.go 2> $err ; then
115
+ echo " FAIL: tsan2"
116
+ status=1
117
+ elif grep -i warning $err > /dev/null 2>&1 ; then
118
+ cat $err
119
+ echo " FAIL: tsan2"
120
+ status=1
121
+ fi
83
122
84
- if go run -msan msan_fail.go 2> /dev/null; then
85
- echo " FAIL: msan_fail"
86
- status=1
123
+ rm -f $err
87
124
fi
88
125
89
126
exit $status
0 commit comments