Skip to contentSkip to conversation

lsmod01: Add kernel module

PATCH Superseded Joerg Vehlow 2 participants 7 messages Sep 27, 2019 – Oct 7, 2019

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lsmod01: Add kernel module

From: Joerg Vehlow <[email protected]>

Forgot calling cleanup in v1

The test fails, if no kernel module is loaded. Now at least one module is always loaded.

---
 testcases/commands/.gitignore          |  1 +
 testcases/commands/lsmod/Makefile      | 15 +++++++++++++++
 testcases/commands/lsmod/lsmod01.sh    | 26 ++++++++++++++++++++++++++
 testcases/commands/lsmod/ltp_lsmod01.c | 26 ++++++++++++++++++++++++++
 4 files changed, 68 insertions(+)
 create mode 100644 testcases/commands/lsmod/ltp_lsmod01.c
testcases/commands/.gitignore +1 -0
index 0ed343881..ed5e13e29 100644
@@ -2,3 +2,4 @@
 /ldd/datafiles/*.obj.so
 /eject/eject_check_tray
 /insmod/ltp_insmod01.ko
+/lsmod/ltp_lsmod01.ko
testcases/commands/lsmod/Makefile +15 -0
index 2af91b3de..8fc3b1436 100644
@@ -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
testcases/commands/lsmod/lsmod01.sh +26 -0
index ad170dcd4..7f9dd284e 100755
@@ -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"
@@ -34,6 +58,8 @@ lsmod_test()
 		return
 	fi
 
+	cleanup
+
 	tst_res TPASS "'lsmod' passed."
 }
 
testcases/commands/lsmod/ltp_lsmod01.c new file +26 -0
new file mode 100644
index 000000000..8ba786276
@@ -0,0 +1,26 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * 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_init(test_init);
+module_exit(test_exit);
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/1 lsmod01: Add kernel module

Hi!

Quoted 81 lines

Forgot calling cleanup in v1

The test fails, if no kernel module is loaded. Now at least one module is always loaded.

---
 testcases/commands/.gitignore          |  1 +
 testcases/commands/lsmod/Makefile      | 15 +++++++++++++++
 testcases/commands/lsmod/lsmod01.sh    | 26 ++++++++++++++++++++++++++
 testcases/commands/lsmod/ltp_lsmod01.c | 26 ++++++++++++++++++++++++++
 4 files changed, 68 insertions(+)
 create mode 100644 testcases/commands/lsmod/ltp_lsmod01.c
testcases/commands/.gitignore +1 -0
index 0ed343881..ed5e13e29 100644
@@ -2,3 +2,4 @@
 /ldd/datafiles/*.obj.so
 /eject/eject_check_tray
 /insmod/ltp_insmod01.ko
+/lsmod/ltp_lsmod01.ko
testcases/commands/lsmod/Makefile +15 -0
index 2af91b3de..8fc3b1436 100644
@@ -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
testcases/commands/lsmod/lsmod01.sh +15 -0
index ad170dcd4..7f9dd284e 100755
@@ -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
+}

testcases/commands/lsmod/lsmod01.sh line 37

Quoted 10 lines
testcases/commands/lsmod/lsmod01.sh +8 -0
+
+
 lsmod_test()
 {
+	insmod "$TST_MODPATH"
+	if [ $? -ne 0 ]; then
+		tst_res TFAIL "insmod failed"
+		return
+	fi
+	inserted=1

This should be in the test setup. Also can insert the module only and only if /proc/modules is empty?

testcases/commands/lsmod/lsmod01.sh lsmod_test() · line 61

Quoted 8 lines
testcases/commands/lsmod/lsmod01.sh +1 -0
 	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"
@@ -34,6 +58,8 @@ lsmod_test()
 		return
 	fi
 
+	cleanup

If you define the cleanup in TST_CLEANUP the library will call it for you, do not call it yourself here.

Quoted 25 lines
testcases/commands/lsmod/lsmod01.sh +0 -0
 	tst_res TPASS "'lsmod' passed."
 }
 
testcases/commands/lsmod/ltp_lsmod01.c new file +16 -0
new file mode 100644
index 000000000..8ba786276
@@ -0,0 +1,26 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * 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)
+{

testcases/commands/lsmod/ltp_lsmod01.c line 26

Quoted 10 lines
testcases/commands/lsmod/ltp_lsmod01.c new file +10 -0
+	return 0;
+}
+
+static void test_exit(void)
+{
+
+}
+
+module_init(test_init);
+module_exit(test_exit);

You are missing the GPL license here, without it the module will taint the kernel.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH v2 1/1 lsmod01: Add kernel module

Hi,

Am 04.10.2019 um 12:34 schrieb Cyril Hrubis:

Quoted 86 lines

Hi!

Quoted 85 lines

Forgot calling cleanup in v1

The test fails, if no kernel module is loaded. Now at least one module is always loaded.

---
  testcases/commands/.gitignore          |  1 +
  testcases/commands/lsmod/Makefile      | 15 +++++++++++++++
  testcases/commands/lsmod/lsmod01.sh    | 26 ++++++++++++++++++++++++++
  testcases/commands/lsmod/ltp_lsmod01.c | 26 ++++++++++++++++++++++++++
  4 files changed, 68 insertions(+)

create mode 100644 testcases/commands/lsmod/ltp_lsmod01.c

testcases/commands/.gitignore +1 -0
index 0ed343881..ed5e13e29 100644
@@ -2,3 +2,4 @@
  /ldd/datafiles/*.obj.so
  /eject/eject_check_tray
  /insmod/ltp_insmod01.ko
+/lsmod/ltp_lsmod01.ko
testcases/commands/lsmod/Makefile +15 -0
index 2af91b3de..8fc3b1436 100644
@@ -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
testcases/commands/lsmod/lsmod01.sh +17 -0
index ad170dcd4..7f9dd284e 100755
@@ -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()
  {
Quoted 8 lines

testcases/commands/lsmod/lsmod01.sh line 37

Quoted 6 lines
testcases/commands/lsmod/lsmod01.sh +6 -0
+	insmod "$TST_MODPATH"
+	if [ $? -ne 0 ]; then
+		tst_res TFAIL "insmod failed"
+		return
+	fi
+	inserted=1

This should be in the test setup. Also can insert the module only and only if /proc/modules is empty?

You are right, I will change it

Quoted 11 lines

testcases/commands/lsmod/lsmod01.sh lsmod_test() · line 61

Quoted 9 lines
testcases/commands/lsmod/lsmod01.sh +1 -0
  	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"
@@ -34,6 +58,8 @@ lsmod_test()
  		return
  	fi
 
+	cleanup

If you define the cleanup in TST_CLEANUP the library will call it for you, do not call it yourself here.

No, if no TST_SETUP is defined, the library will not call it. See tst_test.sh:31:
if[ -n "$TST_SETUP_STARTED" -a -n "$TST_CLEANUP" -a \
??? ???? -z "$TST_NO_CLEANUP" ]; then
??? $TST_CLEANUP
fi
But since I'm going to move the module loading into setup, I can remove this.

Quoted 30 lines
Quoted 30 lines
testcases/commands/lsmod/lsmod01.sh +0 -0
  	tst_res TPASS "'lsmod' passed."
  }
 
testcases/commands/lsmod/ltp_lsmod01.c new file +20 -0
new file mode 100644
index 000000000..8ba786276
@@ -0,0 +1,26 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2016 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * 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)
Quoted 8 lines

testcases/commands/lsmod/ltp_lsmod01.c line 26

Quoted 6 lines
testcases/commands/lsmod/ltp_lsmod01.c new file +6 -0
+{
+
+}
+
+module_init(test_init);
+module_exit(test_exit);

You are missing the GPL license here, without it the module will taint the kernel.

I will add it.

#3 lore raw

PATCH v2 1/1 lsmod01: Add kernel module

Hi!

Quoted 9 lines
Quoted 2 lines

If you define the cleanup in TST_CLEANUP the library will call it for you, do not call it yourself here.

No, if no TST_SETUP is defined, the library will not call it. See tst_test.sh:31:
if[ -n "$TST_SETUP_STARTED" -a -n "$TST_CLEANUP" -a \
?????? ???????? -z "$TST_NO_CLEANUP" ]; then ?????? $TST_CLEANUP
fi

That sounds like a bug in the test library, I will have a look at it later on.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

PATCH v2 1/1 lsmod01: Add kernel module

Hi!

Quoted 9 lines
Quoted 6 lines

No, if no TST_SETUP is defined, the library will not call it. See tst_test.sh:31:
if[ -n "$TST_SETUP_STARTED" -a -n "$TST_CLEANUP" -a \
?????? ???????? -z "$TST_NO_CLEANUP" ]; then ?????? $TST_CLEANUP
fi

That sounds like a bug in the test library, I will have a look at it later on.

I've created GitHub issue #586 so that we do not forget to deal with this, see https://github.com/linux-test-project/ltp/issues/586

Signature · 2 lines
Cyril Hrubis
[email protected]
#5 lore raw

PATCH v2 1/1 lsmod01: Add kernel module

In reply to Cyril Hrubis

Hi,

Quoted 2 lines

You are missing the GPL license here, without it the module will taint the kernel.

The kernel will still be tainted, even if the license is set, because of out-of-tree build.
Do I miss anything?

Quoted 1 line

ltp_lsmod01: loading out-of-tree module taints kernel.

#6 lore raw

PATCH v2 1/1 lsmod01: Add kernel module

Hi!

Quoted 6 lines
Quoted 2 lines

You are missing the GPL license here, without it the module will taint the kernel.

The kernel will still be tainted, even if the license is set, because of out-of-tree build.
Do I miss anything?

The taint is actually a bitfield, we cannot do anything with the out-of-tree one, but the less we turn on the better.

Signature · 2 lines
Cyril Hrubis
[email protected]