changeset 923:aff9fa1075eb

Upgrade modinfo to support multiple modules, and add tests, from Isaac Dunham.
author Rob Landley <rob@landley.net>
date Sun, 16 Jun 2013 02:23:59 -0500
parents 32eec4a8f363
children b792de46d715
files scripts/test/modinfo.test toys/other/modinfo.c
diffstat 2 files changed, 37 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/test/modinfo.test	Sun Jun 16 02:23:59 2013 -0500
@@ -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" "" "" ""
+
+
+
--- a/toys/other/modinfo.c	Sat Jun 15 00:49:06 2013 -0500
+++ b/toys/other/modinfo.c	Sun Jun 16 02:23:59 2013 -0500
@@ -16,6 +16,8 @@
 
 GLOBALS(
   char *field;
+
+  long mod;
 )
 
 static char *modinfo_tags[] = {
@@ -69,10 +71,9 @@
 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 @@
   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);
+  }
 }