Debian Codegraph @

tests/bin/crowdsec-wrapper

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 set -eu
4
5 #
6 # Delegate operations to an instrumented binary and collects coverage data.
7 #
8
9 #shellcheck disable=SC1007
10 THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
11 # no need to change directory, and doing it here would break hub tests
12 # shellcheck disable=SC1091
13 . "${THIS_DIR}/../.environment.sh"
14
15 set -o pipefail # don't let sed hide the statuscode
16 mkdir -p "${LOCAL_DIR}/var/lib/coverage"
17
18 # this would be nice but doesn't work, since the binary is not running in background
19 #_hup() {
20 # echo "pkill -1 crowdsec.cover"
21 # pkill -HUP crowdsec.cover
22 #}
23 #
24 ## relay the "configuration reload" signal
25 #trap _hup SIGHUP
26
27 # we collect rc and output by hand, because setting -o pipefail would trigger a
28 # SIGPIPE.
29 set +e
30
31 # Arguments to crowdsec are passed through a temporary, newline-delimited
32 # file courtesy of github.com/confluentinc/bincover. Coverage data will be
33 # merged at the end of the test run.
34 # The '=' between flags and values is required.
35 output=$("${BIN_DIR}/crowdsec.cover" \
36 -test.run="^TestBincoverRunMain$" \
37 -test.coverprofile="${LOCAL_DIR}/var/lib/coverage/crowdsec-$(date +'%s')-$$-${RANDOM}.out" \
38 -args-file=<(for i; do echo "${i}"; done))
39 rc=$?
40
41 # If there is bincover metadata, we take the status code from there. Otherwise,
42 # we keep the status from the above command.
43 if [[ ${output} =~ (.*)(START_BINCOVER_METADATA[[:space:]]*)(.*)([[:space:]]END_BINCOVER_METADATA) ]]; then
44 echo -n "${BASH_REMATCH[1]}"
45 exit "$(jq '.exit_code' <<< "${BASH_REMATCH[3]}")"
46 fi
47
48 echo -n "${output}"
49 exit "${rc}"