aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/test/modinfo.test30
-rw-r--r--toys/other/modinfo.c11
2 files changed, 37 insertions, 4 deletions
diff --git a/scripts/test/modinfo.test b/scripts/test/modinfo.test
new file mode 100755
index 00000000..ac94ce0f
--- /dev/null
+++ b/scripts/test/modinfo.test
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+[ -e /proc/modules ] || { echo "Skipping test because modules are not supported"; exit 1; }
+
+# modinfo does not need to output fields in a specified order.
+# Instead, there are labelled fields. We can use sort to make up for this.
+# Other issues to beware of are the volatile nature of srcversion and vermagic,
+# which change from kernel to kernel and can be disabled.
+# We grep to remove these.
+
+#We expect they have ne2k-pci as a module.
+
+testing "modinfo gets right number of fields" "modinfo ne2k-pci |cut -d: -f1 |grep -v ver|sort" "alias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nauthor\ndepends\ndescription\nfilename\nlicense\nparm\nparm\nparm\n" "" ""
+testing "modinfo treats - and _ as equivalent" "modinfo ne2k_pci |cut -d: -f1 |grep -v ver|sort" "alias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nauthor\ndepends\ndescription\nfilename\nlicense\nparm\nparm\nparm\n" "" ""
+
+# Output of -F filename should be an absolute path to the module.
+# Otherwise, initrd generating scripts will break.
+
+testing "modinfo -F filename gets absolute path" "[ -e `modinfo -F filename ne2k-pci` ] && echo ne2k-pci " "ne2k-pci\n" "" ""
+
+testing "modinfo supports multiple modules" "modinfo -F filename ne2k-pci 8390 | wc -l" "2\n" "" ""
+
+testing "modinfo does not output filename for bad module" "modinfo -F filename zxcvbnm__9753" "" "" ""
+
+
+
diff --git a/toys/other/modinfo.c b/toys/other/modinfo.c
index da510a1d..501ba27b 100644
--- a/toys/other/modinfo.c
+++ b/toys/other/modinfo.c
@@ -16,6 +16,8 @@ config MODINFO
GLOBALS(
char *field;
+
+ long mod;
)
static char *modinfo_tags[] = {
@@ -69,10 +71,9 @@ static void modinfo_file(struct dirtree *dir)
static int check_module(struct dirtree *new)
{
if (S_ISREG(new->st.st_mode)) {
- char **ss;
+ char *s;
- for (ss = toys.optargs; *ss; ss++) {
- char *s = *ss;
+ for (s = toys.optargs[TT.mod]; *s; s++) {
int len = 0;
// The kernel treats - and _ the same, so we should too.
@@ -97,5 +98,7 @@ void modinfo_main(void)
if (uname(&uts) < 0) perror_exit("bad uname");
sprintf(toybuf, "/lib/modules/%s", uts.release);
- dirtree_read(toybuf, check_module);
+ for(TT.mod = 0; TT.mod<toys.optc; TT.mod++) {
+ dirtree_read(toybuf, check_module);
+ }
}