diff --git a/tests/modalias.prov.collect b/tests/modalias.prov.collect new file mode 100755 index 0000000..deaeaf7 --- /dev/null +++ b/tests/modalias.prov.collect @@ -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 diff --git a/tests/modalias.prov.runtest b/tests/modalias.prov.runtest new file mode 100755 index 0000000..2fbc655 --- /dev/null +++ b/tests/modalias.prov.runtest @@ -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 diff --git a/tests/modalias.prov.testdata.tar.xz b/tests/modalias.prov.testdata.tar.xz new file mode 100644 index 0000000..790d08e Binary files /dev/null and b/tests/modalias.prov.testdata.tar.xz differ