4 # Run leaks with every test profile.
6 # Copyright 2024 Odin Kroeger.
8 # This file is part of Para.
10 # Para is free software: you can redistribute it and/or modify it under
11 # the terms of the GNU General Public License as published by the Free
12 # Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # Para is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 # License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Para. If not, see <https://www.gnu.org/licenses/>.
24 # shellcheck disable=2015,2016,2034,2094
31 scriptdir
="$(cd -P "$
(dirname -- "$0")" && pwd)"
34 rootdir
="$(cd "$scriptdir/..
" && pwd)"
36 : "${BUILDDIR:="$rootdir"}"
37 : "${SRCDIR:="$rootdir"}"
39 readonly BUILDDIR SRCDIR
41 # shellcheck disable=2154
42 export PATH
="$BUILDDIR:$PATH"
44 # shellcheck disable=1091
45 .
"$SRCDIR/libutil.sh" ||
exit
47 # shellcheck disable=2119
50 # Always exit with a status indicating an error unless $fin is set
51 atexit
="${atexit-:}; [ \"\${caught-}\" ] || [ \"\${fin-}\" ] || exit 4"
54 export HAVE_GETLOADAVG NEXTENSIONS
61 # Where to look for test cases
62 testsdir
="$SRCDIR/tests"
67 # Stop at first memory leak?
70 # Options to pass to leaks
78 OPTARG
='' OPTIND
=1 opt
=''
79 while getopts 'dho:qs' opt
83 $progname - run leaks with every test
85 Usage: $progname [-d] [-o opt]... [-q] [-s] [test ...]
89 -d Enable debugging mode.
90 -o opt Pass opt to leaks.
92 -s Stop at first leak.
93 -h Show this help screen.
97 (o
) leaksopts
="$leaksopts$OPTARG " ;;
103 shift $
((OPTIND
- 1))
106 then set -- "$testsdir/integration"
114 readonly findpipe
="$TMPDIR/find.fifo"
122 export MallocCheckZeroOnFreeCorruption
=1
123 export MallocDebugReport
=crash
124 export MallocErrorAbort
=1
125 export MallocGuardEdges
=1
126 export MallocNanoZone
=0
127 export MallocScribble
=1
128 export MallocStackLogging
=1
129 export MallocZeroOnFree
=1
131 find "$@" -type f
! -name '.*' >"$findpipe" & findpid
=$
!
132 failc
=0 passc
=0 runc
=0
135 # shellcheck disable=2119
138 # shellcheck disable=1090
144 if ! [ "${command-}" ]
153 eval "leaks $leaksopts -atExit -quiet -- $command" >/dev
/null
2>&1
158 do unset "${var%%=*}"
162 (0) passc
="$((passc + 1))"
164 (1) failc
="$((failc + 1))"
165 warn
'%s: Detected issue' "$command"
167 (*) err
'leaks %s: Exited with status $d' "$command" "$retval"
170 unset environ
command
172 if [ "$stop" ] && [ "$failc" -gt 0 ]
180 # shellcheck disable=2119
184 warn
-q 'Checked %d test case(s), found %d issue(s)' "$runc" "$failc"