tests: add tests for modalias.prov

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
Denys Vlasenko 2023-05-07 17:36:00 +02:00
parent 7cd7d838cf
commit c39c0162a0
3 changed files with 73 additions and 0 deletions

31
tests/modalias.prov.collect Executable file
View File

@ -0,0 +1,31 @@
#! /bin/bash -efu
# This fetches test data from current system's /lib/modules
# to /tmp/COLLECT
IFS=$'\n'
find /lib/modules | grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$' \
| while IFS='' read -r module; do
modver=$(/sbin/modinfo -F version "$module")
# delete possible extra lines because some modules have *two* version tags. *cough*b44*cough*
modver=${modver%%$'\n'*} # using $'' bashism, avoid running "head -n1" process
# replace any strange chars with underscores.
# [!...] is glob's "match any char not in set" pattern
# (although bash supports [^...] too, it is not standard)
modver=${modver//[!0-9a-zA-Z._]/_}
# only add version tag if it has a version
[ -z "$modver" ] || modver=" = $modver"
d="/tmp/COLLECT$module"
d="${d%/*}"
mkdir -p "$d"
out=`/sbin/modinfo -F alias "$module" \
| sed -E "s,[^][0-9a-zA-Z._:*?/-],_,g; s,(.+),modalias(\\1)$modver,"`
[ "$out" ] || continue
echo "/tmp/COLLECT$module.modalias$modver" >&2
printf '%s\n' "$out" >"/tmp/COLLECT$module.modalias"
done

42
tests/modalias.prov.runtest Executable file
View File

@ -0,0 +1,42 @@
#!/bin/sh
function die()
{
printf '%s\n' "$*" >&2
exit 1
}
set -e
cd modalias.prov.testdata
test -x ../../modalias.prov || die "No ../../modalias.prov"
# Copy and add -t option to modalias.prov
cp ../../modalias.prov modalias.prov
patch -p1 <<"EOF"
--- a/modalias.prov
+++ b/modalias.prov
@@ -86,6 +86,17 @@ combine_modaliases() {
print_modaliases "$class" "$variants" "$pos"
}
+if [ "$#" = 2 ] && [ "$1" = "-t" ]; then
+ cat -- "$2" \
+ | { while read line; do echo "${#line} $line"; done } \
+ | LC_ALL=C sort -u \
+ | combine_modaliases \
+ >"$2.test"
+ echo "Comparing results for $2"
+ diff -u "$2.right" "$2.test" && rm -- "$2.test"
+ exit
+fi
+
for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do
# | head -n1 because some modules have *two* version tags. *cough*b44*cough*
modver=$(/sbin/modinfo -F version "$module"| head -n1)
EOF
find | grep '\.ko.*\.modalias$' | xargs -n1 ./modalias.prov -t
# Rename newly generated .test as .right
#find | grep '\.ko.*\.modalias$' | xargs -I'{}' mv '{}'.test '{}'.right

Binary file not shown.