hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/tools/testing/selftests/kselftest_deps.sh
....@@ -46,11 +46,11 @@
4646 print_targets=0
4747
4848 while getopts "p" arg; do
49
- case $arg in
50
- p)
49
+ case $arg in
50
+ p)
5151 print_targets=1
5252 shift;;
53
- esac
53
+ esac
5454 done
5555
5656 if [ $# -eq 0 ]
....@@ -92,6 +92,10 @@
9292 # Get all TARGETS from selftests Makefile
9393 targets=$(egrep "^TARGETS +|^TARGETS =" Makefile | cut -d "=" -f2)
9494
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
+
9599 # Single test case
96100 if [ $# -eq 2 ]
97101 then
....@@ -100,6 +104,8 @@
100104 l1_test $test
101105 l2_test $test
102106 l3_test $test
107
+ l4_test $test
108
+ l5_test $test
103109
104110 print_results $1 $2
105111 exit $?
....@@ -113,7 +119,7 @@
113119 # Append space at the end of the list to append more tests.
114120
115121 l1_tests=$(grep -r --include=Makefile "^LDLIBS" | \
116
- grep -v "VAR_LDLIBS" | awk -F: '{print $1}')
122
+ grep -v "$filter" | awk -F: '{print $1}' | uniq)
117123
118124 # Level 2: LDLIBS set dynamically.
119125 #
....@@ -126,7 +132,7 @@
126132 # Append space at the end of the list to append more tests.
127133
128134 l2_tests=$(grep -r --include=Makefile ": LDLIBS" | \
129
- grep -v "VAR_LDLIBS" | awk -F: '{print $1}')
135
+ grep -v "$filter" | awk -F: '{print $1}' | uniq)
130136
131137 # Level 3
132138 # gpio, memfd and others use pkg-config to find mount and fuse libs
....@@ -140,11 +146,32 @@
140146 # VAR_LDLIBS := $(shell pkg-config fuse --libs 2>/dev/null)
141147
142148 l3_tests=$(grep -r --include=Makefile "^VAR_LDLIBS" | \
143
- grep -v "pkg-config" | awk -F: '{print $1}')
149
+ grep -v "pkg-config\|PKG_CONFIG" | awk -F: '{print $1}' | uniq)
144150
145
-#echo $l1_tests
146
-#echo $l2_1_tests
147
-#echo $l3_tests
151
+# Level 4
152
+# some tests may fall back to default using `|| echo -l<libname>`
153
+# if pkg-config doesn't find the libs, instead of using VAR_LDLIBS
154
+# as per level 3 checks.
155
+# e.g:
156
+# netfilter/Makefile
157
+# LDLIBS += $(shell $(HOSTPKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl)
158
+l4_tests=$(grep -r --include=Makefile "^LDLIBS" | \
159
+ grep "pkg-config\|PKG_CONFIG" | awk -F: '{print $1}' | uniq)
160
+
161
+# Level 5
162
+# some tests may use IOURING_EXTRA_LIBS to add extra libs to LDLIBS,
163
+# which in turn may be defined in a sub-Makefile
164
+# e.g.:
165
+# mm/Makefile
166
+# $(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS)
167
+l5_tests=$(grep -r --include=Makefile "LDLIBS +=.*\$(IOURING_EXTRA_LIBS)" | \
168
+ awk -F: '{print $1}' | uniq)
169
+
170
+#echo l1_tests $l1_tests
171
+#echo l2_tests $l2_tests
172
+#echo l3_tests $l3_tests
173
+#echo l4_tests $l4_tests
174
+#echo l5_tests $l5_tests
148175
149176 all_tests
150177 print_results $1 $2
....@@ -166,24 +193,32 @@
166193 for test in $l3_tests; do
167194 l3_test $test
168195 done
196
+
197
+ for test in $l4_tests; do
198
+ l4_test $test
199
+ done
200
+
201
+ for test in $l5_tests; do
202
+ l5_test $test
203
+ done
169204 }
170205
171206 # Use same parsing used for l1_tests and pick libraries this time.
172207 l1_test()
173208 {
174209 test_libs=$(grep --include=Makefile "^LDLIBS" $test | \
175
- grep -v "VAR_LDLIBS" | \
210
+ grep -v "$filter" | \
176211 sed -e 's/\:/ /' | \
177212 sed -e 's/+/ /' | cut -d "=" -f 2)
178213
179214 check_libs $test $test_libs
180215 }
181216
182
-# Use same parsing used for l2__tests and pick libraries this time.
217
+# Use same parsing used for l2_tests and pick libraries this time.
183218 l2_test()
184219 {
185220 test_libs=$(grep --include=Makefile ": LDLIBS" $test | \
186
- grep -v "VAR_LDLIBS" | \
221
+ grep -v "$filter" | \
187222 sed -e 's/\:/ /' | sed -e 's/+/ /' | \
188223 cut -d "=" -f 2)
189224
....@@ -199,6 +234,24 @@
199234 check_libs $test $test_libs
200235 }
201236
237
+l4_test()
238
+{
239
+ test_libs=$(grep --include=Makefile "^VAR_LDLIBS\|^LDLIBS" $test | \
240
+ grep "\(pkg-config\|PKG_CONFIG\).*|| echo " | \
241
+ sed -e 's/.*|| echo //' | sed -e 's/)$//')
242
+
243
+ check_libs $test $test_libs
244
+}
245
+
246
+l5_test()
247
+{
248
+ tests=$(find $(dirname "$test") -type f -name "*.mk")
249
+ test_libs=$(grep "^IOURING_EXTRA_LIBS +\?=" $tests | \
250
+ cut -d "=" -f 2)
251
+
252
+ check_libs $test $test_libs
253
+}
254
+
202255 check_libs()
203256 {
204257