0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 usage()
0011 {
0012
0013 echo -e "Usage: $0 -[p] <compiler> [test_name]\n"
0014 echo -e "\tkselftest_deps.sh [-p] gcc"
0015 echo -e "\tkselftest_deps.sh [-p] gcc vm"
0016 echo -e "\tkselftest_deps.sh [-p] aarch64-linux-gnu-gcc"
0017 echo -e "\tkselftest_deps.sh [-p] aarch64-linux-gnu-gcc vm\n"
0018 echo "- Should be run in selftests directory in the kernel repo."
0019 echo "- Checks if Kselftests can be built/cross-built on a system."
0020 echo "- Parses all test/sub-test Makefile to find library dependencies."
0021 echo "- Runs compile test on a trivial C file with LDLIBS specified"
0022 echo " in the test Makefiles to identify missing library dependencies."
0023 echo "- Prints suggested target list for a system filtering out tests"
0024 echo " failed the build dependency check from the TARGETS in Selftests"
0025 echo " main Makefile when optional -p is specified."
0026 echo "- Prints pass/fail dependency check for each tests/sub-test."
0027 echo "- Prints pass/fail targets and libraries."
0028 echo "- Default: runs dependency checks on all tests."
0029 echo "- Optional: test name can be specified to check dependencies for it."
0030 exit 1
0031
0032 }
0033
0034
0035 main()
0036 {
0037
0038 base_dir=`pwd`
0039
0040 if [ $(basename "$base_dir") != "selftests" ]; then
0041 echo -e "\tPlease run $0 in"
0042 echo -e "\ttools/testing/selftests directory ..."
0043 exit 1
0044 fi
0045
0046 print_targets=0
0047
0048 while getopts "p" arg; do
0049 case $arg in
0050 p)
0051 print_targets=1
0052 shift;;
0053 esac
0054 done
0055
0056 if [ $
0057 then
0058 usage
0059 fi
0060
0061
0062 CC=$1
0063
0064 tmp_file=$(mktemp).c
0065 trap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT
0066
0067
0068 pass=$(mktemp).out
0069 trap "rm -f $pass" EXIT
0070
0071
0072 fail=$(mktemp).out
0073 trap "rm -f $fail" EXIT
0074
0075
0076
0077 cat << "EOF" > $tmp_file
0078 int main()
0079 {
0080 }
0081 EOF
0082
0083
0084 total_cnt=0
0085 fail_trgts=()
0086 fail_libs=()
0087 fail_cnt=0
0088 pass_trgts=()
0089 pass_libs=()
0090 pass_cnt=0
0091
0092
0093 targets=$(egrep "^TARGETS +|^TARGETS =" Makefile | cut -d "=" -f2)
0094
0095
0096 if [ $
0097 then
0098 test=$2/Makefile
0099
0100 l1_test $test
0101 l2_test $test
0102 l3_test $test
0103
0104 print_results $1 $2
0105 exit $?
0106 fi
0107
0108
0109
0110
0111
0112
0113
0114
0115 l1_tests=$(grep -r --include=Makefile "^LDLIBS" | \
0116 grep -v "VAR_LDLIBS" | awk -F: '{print $1}')
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128 l2_tests=$(grep -r --include=Makefile ": LDLIBS" | \
0129 grep -v "VAR_LDLIBS" | awk -F: '{print $1}')
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 l3_tests=$(grep -r --include=Makefile "^VAR_LDLIBS" | \
0141 grep -v "pkg-config" | awk -F: '{print $1}')
0142
0143
0144
0145
0146
0147 all_tests
0148 print_results $1 $2
0149
0150 exit $?
0151 }
0152
0153
0154 all_tests()
0155 {
0156 for test in $l1_tests; do
0157 l1_test $test
0158 done
0159
0160 for test in $l2_tests; do
0161 l2_test $test
0162 done
0163
0164 for test in $l3_tests; do
0165 l3_test $test
0166 done
0167 }
0168
0169
0170 l1_test()
0171 {
0172 test_libs=$(grep --include=Makefile "^LDLIBS" $test | \
0173 grep -v "VAR_LDLIBS" | \
0174 sed -e 's/\:/ /' | \
0175 sed -e 's/+/ /' | cut -d "=" -f 2)
0176
0177 check_libs $test $test_libs
0178 }
0179
0180
0181 l2_test()
0182 {
0183 test_libs=$(grep --include=Makefile ": LDLIBS" $test | \
0184 grep -v "VAR_LDLIBS" | \
0185 sed -e 's/\:/ /' | sed -e 's/+/ /' | \
0186 cut -d "=" -f 2)
0187
0188 check_libs $test $test_libs
0189 }
0190
0191 l3_test()
0192 {
0193 test_libs=$(grep --include=Makefile "^VAR_LDLIBS" $test | \
0194 grep -v "pkg-config" | sed -e 's/\:/ /' |
0195 sed -e 's/+/ /' | cut -d "=" -f 2)
0196
0197 check_libs $test $test_libs
0198 }
0199
0200 check_libs()
0201 {
0202
0203 if [[ ! -z "${test_libs// }" ]]
0204 then
0205
0206
0207
0208 for lib in $test_libs; do
0209
0210 let total_cnt+=1
0211 $CC -o $tmp_file.bin $lib $tmp_file > /dev/null 2>&1
0212 if [ $? -ne 0 ]; then
0213 echo "FAIL: $test dependency check: $lib" >> $fail
0214 let fail_cnt+=1
0215 fail_libs+="$lib "
0216 fail_target=$(echo "$test" | cut -d "/" -f1)
0217 fail_trgts+="$fail_target "
0218 targets=$(echo "$targets" | grep -v "$fail_target")
0219 else
0220 echo "PASS: $test dependency check passed $lib" >> $pass
0221 let pass_cnt+=1
0222 pass_libs+="$lib "
0223 pass_trgts+="$(echo "$test" | cut -d "/" -f1) "
0224 fi
0225
0226 done
0227 fi
0228 }
0229
0230 print_results()
0231 {
0232 echo -e "========================================================";
0233 echo -e "Kselftest Dependency Check for [$0 $1 $2] results..."
0234
0235 if [ $print_targets -ne 0 ]
0236 then
0237 echo -e "Suggested Selftest Targets for your configuration:"
0238 echo -e "$targets";
0239 fi
0240
0241 echo -e "========================================================";
0242 echo -e "Checked tests defining LDLIBS dependencies"
0243 echo -e "--------------------------------------------------------";
0244 echo -e "Total tests with Dependencies:"
0245 echo -e "$total_cnt Pass: $pass_cnt Fail: $fail_cnt";
0246
0247 if [ $pass_cnt -ne 0 ]; then
0248 echo -e "--------------------------------------------------------";
0249 cat $pass
0250 echo -e "--------------------------------------------------------";
0251 echo -e "Targets passed build dependency check on system:"
0252 echo -e "$(echo "$pass_trgts" | xargs -n1 | sort -u | xargs)"
0253 fi
0254
0255 if [ $fail_cnt -ne 0 ]; then
0256 echo -e "--------------------------------------------------------";
0257 cat $fail
0258 echo -e "--------------------------------------------------------";
0259 echo -e "Targets failed build dependency check on system:"
0260 echo -e "$(echo "$fail_trgts" | xargs -n1 | sort -u | xargs)"
0261 echo -e "--------------------------------------------------------";
0262 echo -e "Missing libraries system"
0263 echo -e "$(echo "$fail_libs" | xargs -n1 | sort -u | xargs)"
0264 fi
0265
0266 echo -e "--------------------------------------------------------";
0267 echo -e "========================================================";
0268 }
0269
0270 main "$@"