Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: fix dependency checker script

This patch fixes inconsistencies in the parsing rules of the levels 1
and 2 of the kselftest_deps.sh. It was added the levels 4 and 5 to
account for a few edge cases that are present in some tests, also some
minor identation styling have been fixed (s/ /\t/g).

Signed-off-by: Ricardo B. Marliere <rbmarliere@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Ricardo B. Marliere and committed by
Shuah Khan
5f9dd2e8 9616cb34

+65 -12
+65 -12
tools/testing/selftests/kselftest_deps.sh
··· 46 46 print_targets=0 47 47 48 48 while getopts "p" arg; do 49 - case $arg in 50 - p) 49 + case $arg in 50 + p) 51 51 print_targets=1 52 52 shift;; 53 - esac 53 + esac 54 54 done 55 55 56 56 if [ $# -eq 0 ] ··· 92 92 # Get all TARGETS from selftests Makefile 93 93 targets=$(grep -E "^TARGETS +|^TARGETS =" Makefile | cut -d "=" -f2) 94 94 95 + # Initially, in LDLIBS related lines, the dep checker needs 96 + # to ignore lines containing the following strings: 97 + filter="\$(VAR_LDLIBS)\|pkg-config\|PKG_CONFIG\|IOURING_EXTRA_LIBS" 98 + 95 99 # Single test case 96 100 if [ $# -eq 2 ] 97 101 then ··· 104 100 l1_test $test 105 101 l2_test $test 106 102 l3_test $test 103 + l4_test $test 104 + l5_test $test 107 105 108 106 print_results $1 $2 109 107 exit $? ··· 119 113 # Append space at the end of the list to append more tests. 120 114 121 115 l1_tests=$(grep -r --include=Makefile "^LDLIBS" | \ 122 - grep -v "VAR_LDLIBS" | awk -F: '{print $1}') 116 + grep -v "$filter" | awk -F: '{print $1}' | uniq) 123 117 124 118 # Level 2: LDLIBS set dynamically. 125 119 # ··· 132 126 # Append space at the end of the list to append more tests. 133 127 134 128 l2_tests=$(grep -r --include=Makefile ": LDLIBS" | \ 135 - grep -v "VAR_LDLIBS" | awk -F: '{print $1}') 129 + grep -v "$filter" | awk -F: '{print $1}' | uniq) 136 130 137 131 # Level 3 138 132 # memfd and others use pkg-config to find mount and fuse libs ··· 144 138 # VAR_LDLIBS := $(shell pkg-config fuse --libs 2>/dev/null) 145 139 146 140 l3_tests=$(grep -r --include=Makefile "^VAR_LDLIBS" | \ 147 - grep -v "pkg-config" | awk -F: '{print $1}') 141 + grep -v "pkg-config\|PKG_CONFIG" | awk -F: '{print $1}' | uniq) 148 142 149 - #echo $l1_tests 150 - #echo $l2_1_tests 151 - #echo $l3_tests 143 + # Level 4 144 + # some tests may fall back to default using `|| echo -l<libname>` 145 + # if pkg-config doesn't find the libs, instead of using VAR_LDLIBS 146 + # as per level 3 checks. 147 + # e.g: 148 + # netfilter/Makefile 149 + # LDLIBS += $(shell $(HOSTPKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl) 150 + l4_tests=$(grep -r --include=Makefile "^LDLIBS" | \ 151 + grep "pkg-config\|PKG_CONFIG" | awk -F: '{print $1}' | uniq) 152 + 153 + # Level 5 154 + # some tests may use IOURING_EXTRA_LIBS to add extra libs to LDLIBS, 155 + # which in turn may be defined in a sub-Makefile 156 + # e.g.: 157 + # mm/Makefile 158 + # $(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS) 159 + l5_tests=$(grep -r --include=Makefile "LDLIBS +=.*\$(IOURING_EXTRA_LIBS)" | \ 160 + awk -F: '{print $1}' | uniq) 161 + 162 + #echo l1_tests $l1_tests 163 + #echo l2_tests $l2_tests 164 + #echo l3_tests $l3_tests 165 + #echo l4_tests $l4_tests 166 + #echo l5_tests $l5_tests 152 167 153 168 all_tests 154 169 print_results $1 $2 ··· 191 164 for test in $l3_tests; do 192 165 l3_test $test 193 166 done 167 + 168 + for test in $l4_tests; do 169 + l4_test $test 170 + done 171 + 172 + for test in $l5_tests; do 173 + l5_test $test 174 + done 194 175 } 195 176 196 177 # Use same parsing used for l1_tests and pick libraries this time. 197 178 l1_test() 198 179 { 199 180 test_libs=$(grep --include=Makefile "^LDLIBS" $test | \ 200 - grep -v "VAR_LDLIBS" | \ 181 + grep -v "$filter" | \ 201 182 sed -e 's/\:/ /' | \ 202 183 sed -e 's/+/ /' | cut -d "=" -f 2) 203 184 204 185 check_libs $test $test_libs 205 186 } 206 187 207 - # Use same parsing used for l2__tests and pick libraries this time. 188 + # Use same parsing used for l2_tests and pick libraries this time. 208 189 l2_test() 209 190 { 210 191 test_libs=$(grep --include=Makefile ": LDLIBS" $test | \ 211 - grep -v "VAR_LDLIBS" | \ 192 + grep -v "$filter" | \ 212 193 sed -e 's/\:/ /' | sed -e 's/+/ /' | \ 213 194 cut -d "=" -f 2) 214 195 ··· 228 193 test_libs=$(grep --include=Makefile "^VAR_LDLIBS" $test | \ 229 194 grep -v "pkg-config" | sed -e 's/\:/ /' | 230 195 sed -e 's/+/ /' | cut -d "=" -f 2) 196 + 197 + check_libs $test $test_libs 198 + } 199 + 200 + l4_test() 201 + { 202 + test_libs=$(grep --include=Makefile "^VAR_LDLIBS\|^LDLIBS" $test | \ 203 + grep "\(pkg-config\|PKG_CONFIG\).*|| echo " | \ 204 + sed -e 's/.*|| echo //' | sed -e 's/)$//') 205 + 206 + check_libs $test $test_libs 207 + } 208 + 209 + l5_test() 210 + { 211 + tests=$(find $(dirname "$test") -type f -name "*.mk") 212 + test_libs=$(grep "^IOURING_EXTRA_LIBS +\?=" $tests | \ 213 + cut -d "=" -f 2) 231 214 232 215 check_libs $test $test_libs 233 216 }