mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
Format shell scripts with shfmt.
All changes in this patch were performed automatically with `shfmt` with configuration flags specified in `.pre-commit-config.yaml`. In addition to fixing whitespace the roundtrip through shfmt's AST also transforms command substitutions `cmd` # becomes $(cmd) and some redirects >&2 echo "msg" # becomes echo >&2 "msg"
This commit is contained in:
parent
e0b4659488
commit
1f388e3f40
34 changed files with 369 additions and 379 deletions
|
@ -16,69 +16,69 @@
|
|||
# 4a. Analyze .gcov files generated and create summary file
|
||||
# 4b. Send .gcov files to appropriate path
|
||||
#
|
||||
CURR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Location of script
|
||||
BASE="$( cd "$CURR" && cd ../../ && pwd )"
|
||||
CURR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Location of script
|
||||
BASE="$(cd "$CURR" && cd ../../ && pwd)"
|
||||
TMP="${CURR}/tmp.$$"
|
||||
mkdir -p $TMP
|
||||
|
||||
# DEFINE CLEANUP PROCESS
|
||||
function finish {
|
||||
rm -rf $TMP
|
||||
rm -rf $TMP
|
||||
}
|
||||
trap finish EXIT
|
||||
|
||||
# DEFINE CRUCIAL FUNCTIONS FOR COVERAGE CHECKING
|
||||
function check_file_coverage {
|
||||
GCOVDIR="$1"
|
||||
GCOVDIR="$1"
|
||||
|
||||
for i in $GCOVDIR/*.gcov; do
|
||||
# Effective # of lines: starts with a number (# of runs in line) or ##### (line never run)
|
||||
TOTAL=$(cut -d: -f 1 "$i" | sed 's/ //g' | grep -v "^[[:alpha:]]" | grep -v "-" | wc -l)
|
||||
for i in $GCOVDIR/*.gcov; do
|
||||
# Effective # of lines: starts with a number (# of runs in line) or ##### (line never run)
|
||||
TOTAL=$(cut -d: -f 1 "$i" | sed 's/ //g' | grep -v "^[[:alpha:]]" | grep -v "-" | wc -l)
|
||||
|
||||
# Count number of lines never run
|
||||
UNRUN=$(grep "#####" "$i" | wc -l)
|
||||
# Count number of lines never run
|
||||
UNRUN=$(grep "#####" "$i" | wc -l)
|
||||
|
||||
# Lines in code are either run or unrun
|
||||
RUN=$(($TOTAL - $UNRUN))
|
||||
# Lines in code are either run or unrun
|
||||
RUN=$(($TOTAL - $UNRUN))
|
||||
|
||||
# Avoid division-by-zero problems:
|
||||
PERCENTAGE=0.000
|
||||
[ $RUN -gt 0 ] && PERCENTAGE=$(bc <<< "scale=3; 100*$RUN/$TOTAL")
|
||||
# Avoid division-by-zero problems:
|
||||
PERCENTAGE=0.000
|
||||
[ $RUN -gt 0 ] && PERCENTAGE=$(bc <<<"scale=3; 100*$RUN/$TOTAL")
|
||||
|
||||
# Find correlation between % of lines run vs. "Runs"
|
||||
echo -e "$PERCENTAGE\t$RUN\t$TOTAL\t$(grep "0:Runs" "$i" | sed 's/.*://')\t$i"
|
||||
done
|
||||
# Find correlation between % of lines run vs. "Runs"
|
||||
echo -e "$PERCENTAGE\t$RUN\t$TOTAL\t$(grep "0:Runs" "$i" | sed 's/.*://')\t$i"
|
||||
done
|
||||
}
|
||||
|
||||
function check_group_coverage {
|
||||
DATA="$1" # FILE CONTAINING COVERAGE DATA
|
||||
SRC_FOLDER="$2" # WHERE ZEEK WAS COMPILED
|
||||
OUTPUT="$3"
|
||||
DATA="$1" # FILE CONTAINING COVERAGE DATA
|
||||
SRC_FOLDER="$2" # WHERE ZEEK WAS COMPILED
|
||||
OUTPUT="$3"
|
||||
|
||||
# Prints all the relevant directories
|
||||
DIRS=$(for i in $(cut -f 5 "$DATA"); do basename "$i" | sed 's/#[^#]*$//'; done \
|
||||
| sort | uniq | sed 's/^.*'"${SRC_FOLDER}"'//' | grep "^#s\+" )
|
||||
# "Generalize" folders unless it's from analyzers
|
||||
DIRS=$(for i in $DIRS; do
|
||||
if !(echo "$i" | grep "src#analyzer"); then
|
||||
echo "$i" | cut -d "#" -f 1,2,3
|
||||
fi
|
||||
done | sort | uniq )
|
||||
# Prints all the relevant directories
|
||||
DIRS=$(for i in $(cut -f 5 "$DATA"); do basename "$i" | sed 's/#[^#]*$//'; done |
|
||||
sort | uniq | sed 's/^.*'"${SRC_FOLDER}"'//' | grep "^#s\+")
|
||||
# "Generalize" folders unless it's from analyzers
|
||||
DIRS=$(for i in $DIRS; do
|
||||
if !(echo "$i" | grep "src#analyzer"); then
|
||||
echo "$i" | cut -d "#" -f 1,2,3
|
||||
fi
|
||||
done | sort | uniq)
|
||||
|
||||
for i in $DIRS; do
|
||||
# For elements in #src, we only care about the files direclty in the directory.
|
||||
if [[ "$i" = "#src" ]]; then
|
||||
RUN=$(echo $(grep "$i#[^#]\+$" $DATA | grep "$SRC_FOLDER$i\|build$i" | cut -f 2) | tr " " "+" | bc)
|
||||
TOTAL=$(echo $(grep "$i#[^#]\+$" $DATA | grep "$SRC_FOLDER$i\|build$i" | cut -f 3) | tr " " "+" | bc)
|
||||
else
|
||||
RUN=$(echo $(grep "$i" $DATA | cut -f 2) | tr " " "+" | bc)
|
||||
TOTAL=$(echo $(grep "$i" $DATA | cut -f 3) | tr " " "+" | bc)
|
||||
fi
|
||||
for i in $DIRS; do
|
||||
# For elements in #src, we only care about the files direclty in the directory.
|
||||
if [[ "$i" = "#src" ]]; then
|
||||
RUN=$(echo $(grep "$i#[^#]\+$" $DATA | grep "$SRC_FOLDER$i\|build$i" | cut -f 2) | tr " " "+" | bc)
|
||||
TOTAL=$(echo $(grep "$i#[^#]\+$" $DATA | grep "$SRC_FOLDER$i\|build$i" | cut -f 3) | tr " " "+" | bc)
|
||||
else
|
||||
RUN=$(echo $(grep "$i" $DATA | cut -f 2) | tr " " "+" | bc)
|
||||
TOTAL=$(echo $(grep "$i" $DATA | cut -f 3) | tr " " "+" | bc)
|
||||
fi
|
||||
|
||||
PERCENTAGE=$( echo "scale=3;100*$RUN/$TOTAL" | bc | tr "\n" " " )
|
||||
printf "%-50s\t%12s\t%6s %%\n" "$i" "$RUN/$TOTAL" $PERCENTAGE \
|
||||
| sed 's|#|/|g' >>$OUTPUT
|
||||
done
|
||||
PERCENTAGE=$(echo "scale=3;100*$RUN/$TOTAL" | bc | tr "\n" " ")
|
||||
printf "%-50s\t%12s\t%6s %%\n" "$i" "$RUN/$TOTAL" $PERCENTAGE |
|
||||
sed 's|#|/|g' >>$OUTPUT
|
||||
done
|
||||
}
|
||||
|
||||
# 1. Run test suite
|
||||
|
@ -89,7 +89,7 @@ echo -n "Checking for coverage files... "
|
|||
for pat in gcda gcno; do
|
||||
if [ -z "$(find "$BASE" -name "*.$pat" 2>/dev/null)" ]; then
|
||||
echo "no .$pat files, nothing to do"
|
||||
exit 0
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
echo "ok"
|
||||
|
@ -97,24 +97,24 @@ echo "ok"
|
|||
# 3a. Run gcov (-p to preserve path) and move into tmp directory
|
||||
# ... if system does not have gcov installed, exit with message.
|
||||
echo -n "Creating coverage files... "
|
||||
if which gcov > /dev/null 2>&1; then
|
||||
( cd "$TMP" && find "$BASE" -name "*.o" -exec gcov -p {} > /dev/null 2>&1 \; )
|
||||
NUM_GCOVS=$(find "$TMP" -name *.gcov | wc -l)
|
||||
if [ $NUM_GCOVS -eq 0 ]; then
|
||||
echo "no gcov files produced, aborting"
|
||||
exit 1
|
||||
fi
|
||||
if which gcov >/dev/null 2>&1; then
|
||||
(cd "$TMP" && find "$BASE" -name "*.o" -exec gcov -p {} \; >/dev/null 2>&1)
|
||||
NUM_GCOVS=$(find "$TMP" -name *.gcov | wc -l)
|
||||
if [ $NUM_GCOVS -eq 0 ]; then
|
||||
echo "no gcov files produced, aborting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Account for '^' that occurs in macOS due to LLVM
|
||||
# This character seems to be equivalent to ".." (up 1 dir)
|
||||
for file in $(ls $TMP/*.gcov | grep '\^'); do
|
||||
mv $file "$(sed 's/#[^#]*#\^//g' <<< "$file")"
|
||||
done
|
||||
# Account for '^' that occurs in macOS due to LLVM
|
||||
# This character seems to be equivalent to ".." (up 1 dir)
|
||||
for file in $(ls $TMP/*.gcov | grep '\^'); do
|
||||
mv $file "$(sed 's/#[^#]*#\^//g' <<<"$file")"
|
||||
done
|
||||
|
||||
echo "ok, $NUM_GCOVS coverage files"
|
||||
echo "ok, $NUM_GCOVS coverage files"
|
||||
else
|
||||
echo "gcov is not installed on system, aborting"
|
||||
exit 1
|
||||
echo "gcov is not installed on system, aborting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3b. Prune gcov files that fall outside of the Zeek tree:
|
||||
|
@ -134,7 +134,7 @@ echo "ok, $NUM_GCOVS coverage files remain"
|
|||
echo -n "Creating summary file... "
|
||||
DATA="${TMP}/data.txt"
|
||||
SUMMARY="$CURR/coverage.log"
|
||||
check_file_coverage "$TMP" > "$DATA"
|
||||
check_file_coverage "$TMP" >"$DATA"
|
||||
check_group_coverage "$DATA" ${BASE##*/} $SUMMARY
|
||||
echo "ok"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue