Home | History | Annotate | Download | only in lsmod
      1 #!/bin/sh
      2 #
      3 # Copyright (c) 2015 Fujitsu Ltd.
      4 # Author: Guangwen Feng <fenggw-fnst (at] cn.fujitsu.com>
      5 #
      6 # This program is free software; you can redistribute it and/or modify
      7 # it under the terms of the GNU General Public License as published by
      8 # the Free Software Foundation; either version 2 of the License, or
      9 # (at your option) any later version.
     10 #
     11 # This program is distributed in the hope that it will be useful,
     12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
     14 # the GNU General Public License for more details.
     15 #
     16 # Test the basic functionality of lsmod command.
     17 #
     18 TST_TESTFUNC=lsmod_test
     19 TST_NEEDS_TMPDIR=1
     20 TST_NEEDS_CMDS="lsmod"
     21 . tst_test.sh
     22 
     23 lsmod_test()
     24 {
     25 	lsmod_output=$(lsmod | awk '!/Module/{print $1, $2, $3}' | sort)
     26 	if [ -z "$lsmod_output" ]; then
     27 		tst_res TFAIL "Failed to parse the output from lsmod"
     28 		return
     29 	fi
     30 
     31 	modules_output=$(awk '{print $1, $2, $3}' /proc/modules | sort)
     32 	if [ -z "$modules_output" ]; then
     33 		tst_res TFAIL "Failed to parse /proc/modules"
     34 		return
     35 	fi
     36 
     37 	if [ "$lsmod_output" != "$modules_output" ]; then
     38 		tst_res TFAIL "lsmod output different from /proc/modules."
     39 
     40 		echo "$lsmod_output" > temp1
     41 		echo "$modules_output" > temp2
     42 		diff temp1 temp2
     43 
     44 		return
     45 	fi
     46 
     47 	tst_res TPASS "'lsmod' passed."
     48 }
     49 
     50 tst_run
     51