tools/testing/selftests/bpf/test_bpftool_build.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/test_bpftool_build.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/test_bpftool_build.sh
Extension
.sh
Size
3707 bytes
Lines
148
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/bash
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

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 0
		;;
esac

J=$*

# Assume script is located under tools/testing/selftests/bpf/. We want to start
# build attempts from the top of kernel repository.
SCRIPT_REL_PATH=$(realpath --relative-to=$PWD $0)
SCRIPT_REL_DIR=$(dirname $SCRIPT_REL_PATH)
KDIR_ROOT_DIR=$(realpath $PWD/$SCRIPT_REL_DIR/../../../../)
cd $KDIR_ROOT_DIR
if [ ! -e tools/bpf/bpftool/Makefile ]; then
	echo -e "skip:    bpftool files not found!\n"
	exit 4 # KSFT_SKIP=4
fi

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)

	echo -n "binary:  "
	# Returns non-null if file is found (and "false" is run)
	find $dir -type f -executable -name bpftool -print -exec false {} + && \
		ERROR=1 && printf "FAILURE: Did not find bpftool\n"
}

make_and_clean() {
	echo -e "\$PWD:    $PWD"
	echo -e "command: make -s $* >/dev/null"
	make $J -s $* >/dev/null
	if [ $? -ne 0 ] ; then
		ERROR=1
	fi
	if [ $# -ge 1 ] ; then
		check ${@: -1}
	else
		check .
	fi
	(
		if [ $# -ge 1 ] ; then
			cd ${@: -1}
		fi
		make -s clean
	)
	echo
}

make_with_tmpdir() {

Annotation

Implementation Notes