From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joerg Vehlow Date: Fri, 27 Sep 2019 09:43:28 +0200 Subject: [LTP] [PATCH] lsmod01: Add kernel module Message-ID: <20190927074328.10286-1-lkml@jv-coder.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ltp@lists.linux.it From: Joerg Vehlow The test fails, if no kernel module is loaded. Now at least one module is always loaded. Signed-off-by: Joerg Vehlow --- testcases/commands/.gitignore | 1 + testcases/commands/lsmod/Makefile | 15 +++++++++++++++ testcases/commands/lsmod/lsmod01.sh | 24 ++++++++++++++++++++++++ testcases/commands/lsmod/ltp_lsmod01.c | 26 ++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 testcases/commands/lsmod/ltp_lsmod01.c diff --git a/testcases/commands/.gitignore b/testcases/commands/.gitignore index 0ed343881..ed5e13e29 100644 --- a/testcases/commands/.gitignore +++ b/testcases/commands/.gitignore @@ -2,3 +2,4 @@ /ldd/datafiles/*.obj.so /eject/eject_check_tray /insmod/ltp_insmod01.ko +/lsmod/ltp_lsmod01.ko diff --git a/testcases/commands/lsmod/Makefile b/testcases/commands/lsmod/Makefile index 2af91b3de..8fc3b1436 100644 --- a/testcases/commands/lsmod/Makefile +++ b/testcases/commands/lsmod/Makefile @@ -13,10 +13,25 @@ # GNU General Public License for more details. # +ifneq ($(KERNELRELEASE),) + +obj-m := ltp_lsmod01.o + +else + top_srcdir ?= ../../.. +include $(top_srcdir)/include/mk/testcases.mk + +REQ_VERSION_MAJOR := 2 +REQ_VERSION_PATCH := 6 +MAKE_TARGETS := ltp_lsmod01.ko + include $(top_srcdir)/include/mk/env_pre.mk INSTALL_TARGETS := lsmod01.sh +include $(top_srcdir)/include/mk/module.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk + +endif diff --git a/testcases/commands/lsmod/lsmod01.sh b/testcases/commands/lsmod/lsmod01.sh index ad170dcd4..71cdf9ebf 100755 --- a/testcases/commands/lsmod/lsmod01.sh +++ b/testcases/commands/lsmod/lsmod01.sh @@ -5,13 +5,37 @@ # # Test basic functionality of lsmod command. +TST_CLEANUP=cleanup TST_TESTFUNC=lsmod_test TST_NEEDS_TMPDIR=1 TST_NEEDS_CMDS="lsmod" +TST_NEEDS_MODULE="ltp_lsmod01.ko" . tst_test.sh +inserted=0 + +cleanup() +{ + if [ $inserted -ne 0 ]; then + tst_res TINFO "running rmmod ltp_lsmod01" + rmmod ltp_lsmod01 + if [ $? -ne 0 ]; then + tst_res TWARN "failed to rmmod ltp_lsmod01" + fi + inserted=0 + fi +} + + lsmod_test() { + insmod "$TST_MODPATH" + if [ $? -ne 0 ]; then + tst_res TFAIL "insmod failed" + return + fi + inserted=1 + lsmod_output=$(lsmod | awk '!/Module/{print $1, $2, $3}' | sort) if [ -z "$lsmod_output" ]; then tst_res TFAIL "Failed to parse the output from lsmod" diff --git a/testcases/commands/lsmod/ltp_lsmod01.c b/testcases/commands/lsmod/ltp_lsmod01.c new file mode 100644 index 000000000..8ba786276 --- /dev/null +++ b/testcases/commands/lsmod/ltp_lsmod01.c @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (c) 2016 Fujitsu Ltd. + * Author: Guangwen Feng + * + * Description: + * This is a kernel loadable module programme used by lssmod01.sh + * testcase which inserts this module for test of lsmod command. + */ + +#include +#include +#include + +static int test_init(void) +{ + return 0; +} + +static void test_exit(void) +{ + +} + +module_init(test_init); +module_exit(test_exit); -- 2.20.1