~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/test_bpftool_build.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
  3 
  4 case $1 in
  5         -h|--help)
  6                 echo -e "$0 [-j <n>]"
  7                 echo -e "\tTest the different ways of building bpftool."
  8                 echo -e ""
  9                 echo -e "\tOptions:"
 10                 echo -e "\t\t-j <n>:\tPass -j flag to 'make'."
 11                 exit 0
 12                 ;;
 13 esac
 14 
 15 J=$*
 16 
 17 # Assume script is located under tools/testing/selftests/bpf/. We want to start
 18 # build attempts from the top of kernel repository.
 19 SCRIPT_REL_PATH=$(realpath --relative-to=$PWD $0)
 20 SCRIPT_REL_DIR=$(dirname $SCRIPT_REL_PATH)
 21 KDIR_ROOT_DIR=$(realpath $PWD/$SCRIPT_REL_DIR/../../../../)
 22 cd $KDIR_ROOT_DIR
 23 if [ ! -e tools/bpf/bpftool/Makefile ]; then
 24         echo -e "skip:    bpftool files not found!\n"
 25         exit 4 # KSFT_SKIP=4
 26 fi
 27 
 28 ERROR=0
 29 TMPDIR=
 30 
 31 # If one build fails, continue but return non-0 on exit.
 32 return_value() {
 33         if [ -d "$TMPDIR" ] ; then
 34                 rm -rf -- $TMPDIR
 35         fi
 36         exit $ERROR
 37 }
 38 trap return_value EXIT
 39 
 40 check() {
 41         local dir=$(realpath $1)
 42 
 43         echo -n "binary:  "
 44         # Returns non-null if file is found (and "false" is run)
 45         find $dir -type f -executable -name bpftool -print -exec false {} + && \
 46                 ERROR=1 && printf "FAILURE: Did not find bpftool\n"
 47 }
 48 
 49 make_and_clean() {
 50         echo -e "\$PWD:    $PWD"
 51         echo -e "command: make -s $* >/dev/null"
 52         make $J -s $* >/dev/null
 53         if [ $? -ne 0 ] ; then
 54                 ERROR=1
 55         fi
 56         if [ $# -ge 1 ] ; then
 57                 check ${@: -1}
 58         else
 59                 check .
 60         fi
 61         (
 62                 if [ $# -ge 1 ] ; then
 63                         cd ${@: -1}
 64                 fi
 65                 make -s clean
 66         )
 67         echo
 68 }
 69 
 70 make_with_tmpdir() {
 71         local ARGS
 72 
 73         TMPDIR=$(mktemp -d)
 74         if [ $# -ge 2 ] ; then
 75                 ARGS=${@:1:(($# - 1))}
 76         fi
 77         echo -e "\$PWD:    $PWD"
 78         echo -e "command: make -s $ARGS ${@: -1}=$TMPDIR/ >/dev/null"
 79         make $J -s $ARGS ${@: -1}=$TMPDIR/ >/dev/null
 80         if [ $? -ne 0 ] ; then
 81                 ERROR=1
 82         fi
 83         check $TMPDIR
 84         rm -rf -- $TMPDIR
 85         echo
 86 }
 87 
 88 echo "Trying to build bpftool"
 89 echo -e "... through kbuild\n"
 90 
 91 if [ -f ".config" ] ; then
 92         make_and_clean tools/bpf
 93         ## "make tools/bpf" sets $(OUTPUT) to ...tools/bpf/runqslower for
 94         ## runqslower, but the default (used for the "clean" target) is .output.
 95         ## Let's make sure we clean runqslower's directory properly.
 96         make -C tools/bpf/runqslower OUTPUT=${KDIR_ROOT_DIR}/tools/bpf/runqslower/ clean
 97 
 98         ## $OUTPUT is overwritten in kbuild Makefile, and thus cannot be passed
 99         ## down from toplevel Makefile to bpftool's Makefile.
100 
101         # make_with_tmpdir tools/bpf OUTPUT
102         echo -e "skip:    make tools/bpf OUTPUT=<dir> (not supported)\n"
103 
104         make_with_tmpdir tools/bpf O
105 else
106         echo -e "skip:    make tools/bpf (no .config found)\n"
107         echo -e "skip:    make tools/bpf OUTPUT=<dir> (not supported)\n"
108         echo -e "skip:    make tools/bpf O=<dir> (no .config found)\n"
109 fi
110 
111 echo -e "... from kernel source tree\n"
112 
113 make_and_clean -C tools/bpf/bpftool
114 
115 make_with_tmpdir -C tools/bpf/bpftool OUTPUT
116 
117 make_with_tmpdir -C tools/bpf/bpftool O
118 
119 echo -e "... from tools/\n"
120 cd tools/
121 
122 make_and_clean bpf
123 
124 ## In tools/bpf/Makefile, function "descend" is called and passes $(O) and
125 ## $(OUTPUT). We would like $(OUTPUT) to have "bpf/bpftool/" appended before
126 ## calling bpftool's Makefile, but this is not the case as the "descend"
127 ## function focuses on $(O)/$(subdir). However, in the present case, updating
128 ## $(O) to have $(OUTPUT) recomputed from it in bpftool's Makefile does not
129 ## work, because $(O) is not defined from command line and $(OUTPUT) is not
130 ## updated in tools/scripts/Makefile.include.
131 ##
132 ## Workarounds would require to a) edit "descend" or use an alternative way to
133 ## call bpftool's Makefile, b) modify the conditions to update $(OUTPUT) and
134 ## other variables in tools/scripts/Makefile.include (at the risk of breaking
135 ## the build of other tools), or c) append manually the "bpf/bpftool" suffix to
136 ## $(OUTPUT) in bpf's Makefile, which may break if targets for other directories
137 ## use "descend" in the future.
138 
139 # make_with_tmpdir bpf OUTPUT
140 echo -e "skip:    make bpf OUTPUT=<dir> (not supported)\n"
141 
142 make_with_tmpdir bpf O
143 
144 echo -e "... from bpftool's dir\n"
145 cd bpf/bpftool
146 
147 make_and_clean
148 
149 make_with_tmpdir OUTPUT
150 
151 make_with_tmpdir O

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php