Upgrade modinfo to support multiple modules, and add tests, from Isaac Dunham.
authorRob Landley <rob@landley.net>
Sun, 16 Jun 2013 07:23:59 +0000 (02:23 -0500)
committerRob Landley <rob@landley.net>
Sun, 16 Jun 2013 07:23:59 +0000 (02:23 -0500)
scripts/test/modinfo.test [new file with mode: 0755]
toys/other/modinfo.c

diff --git a/scripts/test/modinfo.test b/scripts/test/modinfo.test
new file mode 100755 (executable)
index 0000000..ac94ce0
--- /dev/null
@@ -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" "" "" ""
+
+
+
index da510a1..501ba27 100644 (file)
@@ -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);
+  }
 }