File: sanitize

package info (click to toggle)
btllib 1.4.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,340 kB
  • sloc: cpp: 61,642; sh: 301; python: 222; makefile: 6
file content (77 lines) | stat: -rwxr-xr-x 1,956 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash

set -e

if [ -z "${MESON_SOURCE_ROOT}" ]; then
  echo "[ERROR] This script can only be ran with meson!"
  exit 1
fi

if [ "$#" -ne 1 ]; then
    echo "Must provide the sanitation mode."
    echo "sanitize <address|memory|thread|undefined>"
    exit -1
fi

possible_options=( "address" "memory" "thread" "undefined" )
if [[ ! " ${possible_options[*]} " =~ " ${1} " ]]; then
  echo "The option must be one of the following: address, memory, thread, undefined"
  exit -1
fi

cd "${MESON_SOURCE_ROOT}"

case ${1} in
  address)
    builddir="${MESON_BUILD_ROOT}/__build-sanitize-address"
    meson setup -Db_sanitize=address ${builddir}
    ;;
  memory)
    # Check if clang is present
    set +e
    command -v clang >/dev/null
    if [[ $? -eq 1 ]]; then
      echo "[ERROR] Clang compiler must be used for memory sanitization, but it is missing!"
      exit 1
    fi
    set -e

    # GCC does not seem to support memory sanitization
    export CXX=clang
    export CC=clang

    builddir="${MESON_BUILD_ROOT}/__build-sanitize-memory"
    meson setup -Db_sanitize=memory ${builddir} -Db_lundef=false
    ;;
  thread)
    # Check if clang is present
    set +e
    command -v clang >/dev/null
    if [[ $? -eq 1 ]]; then
      echo "[ERROR] Clang compiler must be used for thread sanitization, but it is missing!"
      exit 1
    fi
    set -e

    # GCC gives false positives when sanitizing threads if OpenMP is used
    # Clang on the other hand seems to handle this properly
    export CXX=clang
    export CC=clang
    export TSAN_OPTIONS='ignore_noninstrumented_modules=1'

    builddir="${MESON_BUILD_ROOT}/__build-sanitize-thread"
    meson setup -Db_sanitize=thread ${builddir} -Db_lundef=false
    ;;
  undefined)
    builddir="${MESON_BUILD_ROOT}/__build-sanitize-undefined"
    meson setup -Db_sanitize=undefined ${builddir}
    ;;
  *)
    echo "Invalid option."
    exit -1
    ;;
esac

cd ${builddir}
ninja test
rm -rf ${builddir}