2015-09-29 22:24:13 -06:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
# This directory is intended to test the use of Go with sanitizers
|
|
|
|
# like msan, asan, etc. See https://github.com/google/sanitizers .
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# The sanitizers were originally developed with clang, so prefer it.
|
|
|
|
CC=cc
|
2015-11-09 13:22:52 -07:00
|
|
|
if test -x "$(type -p clang)"; then
|
2015-09-29 22:24:13 -06:00
|
|
|
CC=clang
|
|
|
|
fi
|
|
|
|
export CC
|
|
|
|
|
2015-11-03 08:14:22 -07:00
|
|
|
TMPDIR=${TMPDIR:-/tmp}
|
|
|
|
echo > ${TMPDIR}/testsanitizers$$.c
|
|
|
|
if $CC -fsanitize=memory -c ${TMPDIR}/testsanitizers$$.c 2>&1 | grep "unrecognized" >& /dev/null; then
|
2015-09-29 22:24:13 -06:00
|
|
|
echo "skipping msan test: -fsanitize=memory not supported"
|
2015-11-03 08:14:22 -07:00
|
|
|
rm -f ${TMPDIR}/testsanitizers$$.*
|
2015-10-02 08:04:34 -06:00
|
|
|
exit 0
|
2015-09-29 22:24:13 -06:00
|
|
|
fi
|
2015-11-03 08:14:22 -07:00
|
|
|
rm -f ${TMPDIR}/testsanitizers$$.*
|
2015-10-02 08:04:34 -06:00
|
|
|
|
|
|
|
# The memory sanitizer in versions of clang before 3.6 don't work with Go.
|
|
|
|
if $CC --version | grep clang >& /dev/null; then
|
|
|
|
ver=$($CC --version | sed -e 's/.* version \([0-9.-]*\).*/\1/')
|
|
|
|
major=$(echo $ver | sed -e 's/\([0-9]*\).*/\1/')
|
|
|
|
minor=$(echo $ver | sed -e 's/[0-9]*\.\([0-9]*\).*/\1/')
|
|
|
|
if test $major -lt 3 || test $major -eq 3 -a $minor -lt 6; then
|
|
|
|
echo "skipping msan test; clang version $major.$minor older than 3.6"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-10-21 13:33:56 -06:00
|
|
|
status=0
|
|
|
|
|
2015-10-26 14:58:23 -06:00
|
|
|
if ! go build -msan std; then
|
|
|
|
echo "FAIL: build -msan std"
|
|
|
|
status=1
|
|
|
|
fi
|
|
|
|
|
2015-10-21 13:33:56 -06:00
|
|
|
if ! go run -msan msan.go; then
|
|
|
|
echo "FAIL: msan"
|
|
|
|
status=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! go run -msan msan2.go; then
|
|
|
|
echo "FAIL: msan2"
|
|
|
|
status=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if go run -msan msan_fail.go 2>/dev/null; then
|
|
|
|
echo "FAIL: msan_fail"
|
|
|
|
status=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $status
|