github.com/q45/go@v0.0.0-20151101211701-a4fb8c13db3f/misc/cgo/testsanitizers/test.bash (about) 1 #!/usr/bin/env bash 2 # Copyright 2015 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 # This directory is intended to test the use of Go with sanitizers 7 # like msan, asan, etc. See https://github.com/google/sanitizers . 8 9 set -e 10 11 # The sanitizers were originally developed with clang, so prefer it. 12 CC=cc 13 if test "$(type -p clang)" != ""; then 14 CC=clang 15 fi 16 export CC 17 18 if $CC -fsanitize=memory 2>&1 | grep "unrecognized" >& /dev/null; then 19 echo "skipping msan test: -fsanitize=memory not supported" 20 exit 0 21 fi 22 23 # The memory sanitizer in versions of clang before 3.6 don't work with Go. 24 if $CC --version | grep clang >& /dev/null; then 25 ver=$($CC --version | sed -e 's/.* version \([0-9.-]*\).*/\1/') 26 major=$(echo $ver | sed -e 's/\([0-9]*\).*/\1/') 27 minor=$(echo $ver | sed -e 's/[0-9]*\.\([0-9]*\).*/\1/') 28 if test $major -lt 3 || test $major -eq 3 -a $minor -lt 6; then 29 echo "skipping msan test; clang version $major.$minor older than 3.6" 30 exit 0 31 fi 32 fi 33 34 status=0 35 36 if ! go run -msan msan.go; then 37 echo "FAIL: msan" 38 status=1 39 fi 40 41 if ! go run -msan msan2.go; then 42 echo "FAIL: msan2" 43 status=1 44 fi 45 46 if go run -msan msan_fail.go 2>/dev/null; then 47 echo "FAIL: msan_fail" 48 status=1 49 fi 50 51 exit $status