modinfo.test 1.9 KB

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