# HG changeset patch # User Rob Landley # Date 1371367439 18000 # Node ID aff9fa1075ebc679d5dd20bb9e7a58a7904d0ab7 # Parent 32eec4a8f36383619f8f330faccd62f4f518801e Upgrade modinfo to support multiple modules, and add tests, from Isaac Dunham. diff -r 32eec4a8f363 -r aff9fa1075eb scripts/test/modinfo.test --- /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" "" "" "" + + + diff -r 32eec4a8f363 -r aff9fa1075eb toys/other/modinfo.c --- 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