From: Joerg Vehlow <lkml@jv-coder.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 3/3] lsmod01: Add kernel module
Date: Tue, 10 Dec 2019 09:04:19 +0100 [thread overview]
Message-ID: <20191210080419.128773-4-lkml@jv-coder.de> (raw)
In-Reply-To: <20191210080419.128773-1-lkml@jv-coder.de>
From: Joerg Vehlow <joerg.vehlow@aox-tech.de>
The test fails, if no kernel module is loaded. Now at least one module is
always loaded.
Signed-off-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
---
testcases/commands/.gitignore | 1 +
testcases/commands/lsmod/Makefile | 15 ++++++++++++
testcases/commands/lsmod/lsmod01.sh | 33 ++++++++++++++++++++++++++
testcases/commands/lsmod/ltp_lsmod01.c | 28 ++++++++++++++++++++++
4 files changed, 77 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 0f5b6aaae..992199fa8 100755
--- a/testcases/commands/lsmod/lsmod01.sh
+++ b/testcases/commands/lsmod/lsmod01.sh
@@ -5,11 +5,44 @@
#
# Test basic functionality of lsmod command.
+TST_CLEANUP=cleanup
+TST_SETUP=setup
TST_TESTFUNC=lsmod_test
TST_NEEDS_TMPDIR=1
TST_NEEDS_CMDS="lsmod"
. tst_test.sh
+module_inserted=0
+
+setup()
+{
+ if [ -z "$(cat /proc/modules)" ]; then
+ tst_res TINFO "Loading dummy kernel module"
+ tst_require_module "ltp_lsmod01.ko"
+ tst_require_root
+ tst_require_cmds insmod
+ insmod "$TST_MODPATH"
+ if [ $? -ne 0 ]; then
+ tst_res TBROK "insmod failed"
+ return
+ fi
+
+ module_inserted=1
+ fi
+}
+
+cleanup()
+{
+ if [ $module_inserted -ne 0 ]; then
+ tst_res TINFO "Unloading dummy kernel module"
+ rmmod ltp_lsmod01
+ if [ $? -ne 0 ]; then
+ tst_res TWARN "rmmod failed"
+ fi
+ module_inserted=0
+ fi
+}
+
lsmod_matches_proc_modules()
{
lsmod_output=$(lsmod | awk '!/Module/{print $1, $2, $3}' | sort)
diff --git a/testcases/commands/lsmod/ltp_lsmod01.c b/testcases/commands/lsmod/ltp_lsmod01.c
new file mode 100644
index 000000000..19f9d9145
--- /dev/null
+++ b/testcases/commands/lsmod/ltp_lsmod01.c
@@ -0,0 +1,28 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Fujitsu Ltd.
+ * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+ *
+ * Description:
+ * This is a kernel loadable module programme used by lssmod01.sh
+ * testcase which inserts this module for test of lsmod command.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+
+static int test_init(void)
+{
+ return 0;
+}
+
+static void test_exit(void)
+{
+
+}
+
+MODULE_LICENSE("GPL");
+
+module_init(test_init);
+module_exit(test_exit);
--
2.20.1
next prev parent reply other threads:[~2019-12-10 8:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-10 8:04 [LTP] [PATCH v4] lsmod01: Add kernel module Joerg Vehlow
2019-12-10 8:04 ` [LTP] [PATCH v4 1/3] tst_test.sh: Add tst_require_module command Joerg Vehlow
2019-12-10 8:04 ` [LTP] [PATCH v4 2/3] tst_test.sh: Make public tst_require_root command public Joerg Vehlow
2019-12-10 8:04 ` Joerg Vehlow [this message]
2020-03-05 13:08 ` [LTP] [PATCH v4 3/3] lsmod01: Add kernel module Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191210080419.128773-4-lkml@jv-coder.de \
--to=lkml@jv-coder.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox