1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5#testing "name" "command" "result" "infile" "stdin" 6 7# Android keeps its modules (if any) on the vendor partition. 8# Don't need to quote variable expansions: no kernel version or 9# module name should ever have a space in it. 10MODULE_ROOT=/vendor/lib/modules 11[ -d $MODULE_ROOT ] || MODULE_ROOT=/lib/modules/$(uname -r) 12 13no_modules() { 14 echo "$SHOWSKIP: modinfo (no modules)" 15 exit 16} 17 18[[ ! -e /proc/modules || ! -d $MODULE_ROOT ]] && no_modules 19 20# Find some modules to work with. 21# Don't need to quote wildcards because test runs in an empty dir. 22MODULE_PATH1=$(find $MODULE_ROOT -name *.ko | head -1) 23[ ! -e "$MODULE_PATH1" ] && no_modules 24MODULE1=$(basename -s .ko $MODULE_PATH1) 25MODULE_PATH2=$(find $MODULE_ROOT -name *.ko | head -2 | tail -1) 26MODULE2=$(basename -s .ko $MODULE_PATH2) 27DASH_MODULE=$(basename -s .ko $(find $MODULE_ROOT -name *-*.ko | tail -1)) 28BAR_MODULE=$(basename -s .ko $(find $MODULE_ROOT -name *_*.ko | tail -1)) 29 30testcmd "missing" "missing 2>&1" "modinfo: missing: not found\n" "" "" 31 32# modinfo does not need to output fields in a specified order. 33# Instead, there are labelled fields. We can use sort to make up for this. 34# Other issues to beware of are the volatile nature of srcversion and vermagic, 35# which change from kernel to kernel and can be disabled: grep to remove these. 36 37skipnot [ -n "$DASH_MODULE" ] 38testing "treats - and _ as equivalent" "modinfo $DASH_MODULE > dash-dash && 39 modinfo ${DASH_MODULE/-/_} > dash-bar && diff -u dash-dash dash-bar" "" "" "" 40skipnot [ -n "$BAR_MODULE" ] 41testing "treats _ and - as equivalent" "modinfo $BAR_MODULE > bar-bar && 42 modinfo ${BAR_MODULE/_/-} > bar-dash && diff -u bar-bar bar-dash" "" "" "" 43 44# Output of -F filename should be an absolute path to the module. 45# Otherwise, initrd generating scripts will break. 46 47testing "-F filename gets absolute path" "modinfo -F filename $MODULE1" \ 48 "$MODULE_PATH1\n" "" "" 49 50skipnot [ "$MODULE1" != "$MODULE2" ] 51testing "supports multiple modules" "modinfo -F filename $MODULE1 $MODULE2" \ 52 "$MODULE_PATH1\n$MODULE_PATH2\n" "" "" 53