#!/bin/bash # SPDX-License-Identifier: GPL-2.0 # kselftest_deps.sh # # Checks for kselftest build dependencies on the build system. # Copyright (c) 2020 Shuah Khan <skhan@linuxfoundation.org> # #
usage()
{
echo -e "Usage: $0 -[p] [test_name]\n" echo -e "\tkselftest_deps.sh [-p] gcc" echo -e "\tkselftest_deps.sh [-p] gcc mm" echo -e "\tkselftest_deps.sh [-p] aarch64-linux-gnu-gcc" echo -e "\tkselftest_deps.sh [-p] aarch64-linux-gnu-gcc mm\n" echo"- Should be run in selftests directory in the kernel repo." echo"- Checks if Kselftests can be built/cross-built on a system." echo"- Parses all test/sub-test Makefile to find library dependencies." echo"- Runs compile test on a trivial C file with LDLIBS specified" echo" in the test Makefiles to identify missing library dependencies." echo"- Prints suggested target list for a system filtering out tests" echo" failed the build dependency check from the TARGETS in Selftests" echo" main Makefile when optional -p is specified." echo"- Prints pass/fail dependency check for each tests/sub-test." echo"- Prints pass/fail targets and libraries." echo"- Default: runs dependency checks on all tests." echo"- Optional: test name can be specified to check dependencies for it."
exit 1
}
# Start main()
main()
{
base_dir=`pwd` # Make sure we're in the selftests top-level directory. if [ $(basename "$base_dir") != "selftests" ]; then echo -e "\tPlease run $0 in" echo -e "\ttools/testing/selftests directory ..."
exit 1 fi
print_targets=0
while getopts "p" arg; do
case $arg in
p)
print_targets=1
shift;;
esac done
# Generate tmp source fire for compile test cat << "EOF" > $tmp_file
int main()
{
}
EOF
# Save results
total_cnt=0
fail_trgts=()
fail_libs=()
fail_cnt=0
pass_trgts=()
pass_libs=()
pass_cnt=0
# Get all TARGETS from selftests Makefile
targets=$(grep -E "^TARGETS +|^TARGETS =" Makefile | cut -d "=" -f2)
# Initially, in LDLIBS related lines, the dep checker needs # to ignore lines containing the following strings:
filter="\$(VAR_LDLIBS)\|pkg-config\|PKG_CONFIG\|IOURING_EXTRA_LIBS"
# Single test case if [ $# -eq 2 ] then
test=$2/Makefile
# Level 1: LDLIBS set static. # # Find all LDLIBS set statically for all executables built by a Makefile # and filter out VAR_LDLIBS to discard the following: # gpio/Makefile:LDLIBS += $(VAR_LDLIBS) # Append space at the end of the list to append more tests.
# Level 2: LDLIBS set dynamically. # # Level 2 # Some tests have multiple valid LDLIBS lines for individual sub-tests # that need dependency checks. Find them and append them to the tests # e.g: mm/Makefile:$(OUTPUT)/userfaultfd: LDLIBS += -lpthread # Filter out VAR_LDLIBS to discard the following: # memfd/Makefile:$(OUTPUT)/fuse_mnt: LDLIBS += $(VAR_LDLIBS) # Append space at the end of the list to append more tests.
# Level 3 # memfd and others use pkg-config to find mount and fuse libs # respectively and save it in VAR_LDLIBS. If pkg-config doesn't find # any, VAR_LDLIBS set to default. # Use the default value and filter out pkg-config for dependency check. # e.g: # memfd/Makefile # VAR_LDLIBS := $(shell pkg-config fuse --libs 2>/dev/null)
# Level 4 # some tests may fall back to default using `|| echo -l<libname>` # if pkg-config doesn't find the libs, instead of using VAR_LDLIBS # as per level 3 checks. # e.g: # netfilter/Makefile # LDLIBS += $(shell $(HOSTPKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl)
l4_tests=$(grep -r --include=Makefile "^LDLIBS" | \
grep "pkg-config\|PKG_CONFIG" | awk -F: '{print $1}' | uniq)
# Level 5 # some tests may use IOURING_EXTRA_LIBS to add extra libs to LDLIBS, # which in turn may be defined in a sub-Makefile # e.g.: # mm/Makefile # $(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS)
l5_tests=$(grep -r --include=Makefile "LDLIBS +=.*\$(IOURING_EXTRA_LIBS)" | \
awk -F: '{print $1}' | uniq)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.