github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/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  fi
    37  
    38  status=0
    39  
    40  if ! go build -msan std; then
    41    echo "FAIL: build -msan std"
    42    status=1
    43  fi
    44  
    45  if ! go run -msan msan.go; then
    46    echo "FAIL: msan"
    47    status=1
    48  fi
    49  
    50  if ! go run -msan msan2.go; then
    51    echo "FAIL: msan2"
    52    status=1
    53  fi
    54  
    55  if ! go run -msan msan3.go; then
    56    echo "FAIL: msan3"
    57    status=1
    58  fi
    59  
    60  if ! go run -msan msan4.go; then
    61    echo "FAIL: msan4"
    62    status=1
    63  fi
    64  
    65  if go run -msan msan_fail.go 2>/dev/null; then
    66    echo "FAIL: msan_fail"
    67    status=1
    68  fi
    69  
    70  exit $status