Skip to content

Commit

Permalink
selftests, bpftool: Set EXIT trap after usage function
Browse files Browse the repository at this point in the history
The trap on EXIT is used to clean up any temporary directory left by the
build attempts. It is not needed when the user simply calls the script
with its --help option, and may not be needed either if we add checks
(e.g. on the availability of bpftool files) before the build attempts.

Let's move this trap and related variables lower down in the code, so
that we don't accidentally change the value returned from the script
on early exits at pre-checks.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Link: https://lore.kernel.org/bpf/20191119105010.19189-2-quentin.monnet@netronome.com
  • Loading branch information
Quentin Monnet authored and Alexei Starovoitov committed Nov 25, 2019
1 parent a89b2cb commit 31f8b82
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tools/testing/selftests/bpf/test_bpftool_build.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
#!/bin/bash
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

ERROR=0
TMPDIR=

# If one build fails, continue but return non-0 on exit.
return_value() {
if [ -d "$TMPDIR" ] ; then
rm -rf -- $TMPDIR
fi
exit $ERROR
}
trap return_value EXIT

case $1 in
-h|--help)
echo -e "$0 [-j <n>]"
echo -e "\tTest the different ways of building bpftool."
echo -e ""
echo -e "\tOptions:"
echo -e "\t\t-j <n>:\tPass -j flag to 'make'."
exit
exit 0
;;
esac

Expand All @@ -33,6 +21,18 @@ SCRIPT_REL_DIR=$(dirname $SCRIPT_REL_PATH)
KDIR_ROOT_DIR=$(realpath $PWD/$SCRIPT_REL_DIR/../../../../)
cd $KDIR_ROOT_DIR

ERROR=0
TMPDIR=

# If one build fails, continue but return non-0 on exit.
return_value() {
if [ -d "$TMPDIR" ] ; then
rm -rf -- $TMPDIR
fi
exit $ERROR
}
trap return_value EXIT

check() {
local dir=$(realpath $1)

Expand Down

0 comments on commit 31f8b82

Please sign in to comment.