github.com/fjballest/golang@v0.0.0-20151209143359-e4c5fe594ca8/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 -x "$(type -p clang)"; then 14 CC=clang 15 fi 16 export CC 17 18 TMPDIR=${TMPDIR:-/tmp} 19 echo > ${TMPDIR}/testsanitizers$$.c 20 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 24 fi 25 rm -f ${TMPDIR}/testsanitizers$$.* 26 27 # 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 ver=$($CC --version | sed -e 's/.* version \([0-9.-]*\).*/\1/') 30 major=$(echo $ver | sed -e 's/\([0-9]*\).*/\1/') 31 minor=$(echo $ver | sed -e 's/[0-9]*\.\([0-9]*\).*/\1/') 32 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 35 fi 36 37 # Clang before 3.8 does not work with Linux at or after 4.1. 38 # golang.org/issue/12898. 39 if test "$major" -lt 3 || test "$major" -eq 3 -a "$minor" -lt 8; then 40 if test "$(uname)" = Linux; then 41 linuxver=$(uname -r) 42 linuxmajor=$(echo $linuxver | sed -e 's/\([0-9]*\).*/\1/') 43 linuxminor=$(echo $linuxver | sed -e 's/[0-9]*\.\([0-9]*\).*/\1/') 44 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 47 fi 48 fi 49 fi 50 fi 51 52 status=0 53 54 if ! go build -msan std; then 55 echo "FAIL: build -msan std" 56 status=1 57 fi 58 59 if ! go run -msan msan.go; then 60 echo "FAIL: msan" 61 status=1 62 fi 63 64 if ! go run -msan msan2.go; then 65 echo "FAIL: msan2" 66 status=1 67 fi 68 69 if ! go run -msan msan3.go; then 70 echo "FAIL: msan3" 71 status=1 72 fi 73 74 if ! go run -msan msan4.go; then 75 echo "FAIL: msan4" 76 status=1 77 fi 78 79 if go run -msan msan_fail.go 2>/dev/null; then 80 echo "FAIL: msan_fail" 81 status=1 82 fi 83 84 exit $status