• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
8MODULE_ROOT=""
9[ -d /vendor/lib/modules ] && MODULE_ROOT="/vendor"
10
11if [[ ! -e /proc/modules || ! -d $MODULE_ROOT/lib/modules ]]; then
12  echo "$SHOWSKIP: modinfo (no modules)"
13  return 2>/dev/null
14  exit
15fi
16
17testcmd "missing" "missing 2>&1" "modinfo: missing: not found\n" "" ""
18
19# Find some modules to work with.
20MODULE_PATH1=$(find $MODULE_ROOT/lib/modules -name *.ko | head -1 2>/dev/null)
21MODULE1=$(basename -s .ko $MODULE_PATH1)
22MODULE_PATH2=$(find $MODULE_ROOT/lib/modules -name *.ko | head -2 | tail -1 2>/dev/null)
23MODULE2=$(basename -s .ko $MODULE_PATH2)
24DASH_MODULE=$(basename -s .ko \
25  $(find $MODULE_ROOT/lib/modules -name *-*.ko | tail -1 2>/dev/null))
26BAR_MODULE=$(basename -s .ko \
27  $(find $MODULE_ROOT/lib/modules -name *_*.ko | tail -1 2>/dev/null))
28
29# modinfo does not need to output fields in a specified order.
30# Instead, there are labelled fields.  We can use sort to make up for this.
31# Other issues to beware of are the volatile nature of srcversion and vermagic,
32# which change from kernel to kernel and can be disabled.
33# We grep to remove these.
34
35skipnot [ -n "$DASH_MODULE" ]
36testing "treats - and _ as equivalent" "modinfo $DASH_MODULE > dash-dash &&
37  modinfo ${DASH_MODULE/-/_} > dash-bar && diff -u dash-dash dash-bar" "" "" ""
38skipnot [ -n "$BAR_MODULE" ]
39testing "treats _ and - as equivalent" "modinfo $BAR_MODULE > bar-bar &&
40  modinfo ${BAR_MODULE/_/-} > bar-dash && diff -u bar-bar bar-dash" "" "" ""
41
42# Output of -F filename should be an absolute path to the module.
43# Otherwise, initrd generating scripts will break.
44
45testing "-F filename gets absolute path" "modinfo -F filename $MODULE1" \
46  "$MODULE_PATH1\n" "" ""
47
48skipnot [ "$MODULE1" != "$MODULE2" ]
49testing "supports multiple modules" "modinfo -F filename $MODULE1 $MODULE2" \
50  "$MODULE_PATH1\n$MODULE_PATH2\n" "" ""
51