Skip to contentSkip to conversation

commands/lsmod: Added new testcase to test lsmod(8)

PATCH Superseded Guangwen Feng 2 participants 10 messages Dec 18, 2015 – May 10, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 commands/lsmod: Added new testcase to test lsmod(8)

Test the basic functionality of lsmod(8) command.

---
 runtest/commands                    |  1 +
 testcases/commands/lsmod/Makefile   | 22 +++++++++++
 testcases/commands/lsmod/lsmod01.sh | 74 +++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+)
 create mode 100644 testcases/commands/lsmod/Makefile
 create mode 100755 testcases/commands/lsmod/lsmod01.sh
runtest/commands +1 -0
index ab600dc..c1ee9f8 100644
@@ -39,3 +39,4 @@ mkfs01_msdos mkfs01.sh -f msdos
 mkfs01_vfat mkfs01.sh -f vfat
 mkfs01_ntfs mkfs01.sh -f ntfs
 mkswap01 mkswap01.sh
+lsmod01 lsmod01.sh
testcases/commands/lsmod/Makefile new file +22 -0
new file mode 100644
index 0000000..2af91b3
@@ -0,0 +1,22 @@
+#
+#    Copyright (c) 2015 Fujitsu Ltd.
+#    Author:Guangwen Feng <[email protected]>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= lsmod01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/commands/lsmod/lsmod01.sh new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
1.8.4.2
#1 lore raw

PATCH 2/2 commands/insmod: Added new testcase to test insmod(8)

Test the basic functionality of insmod(8) command.

---
 runtest/commands                          |  1 +
 testcases/commands/insmod/Makefile        | 36 ++++++++++++++
 testcases/commands/insmod/insmod01.sh     | 79 +++++++++++++++++++++++++++++++
 testcases/commands/insmod/test_insmod01.c | 35 ++++++++++++++
 4 files changed, 151 insertions(+)
 create mode 100644 testcases/commands/insmod/Makefile
 create mode 100755 testcases/commands/insmod/insmod01.sh
 create mode 100644 testcases/commands/insmod/test_insmod01.c
runtest/commands +1 -0
index c1ee9f8..b377081 100644
@@ -40,3 +40,4 @@ mkfs01_vfat mkfs01.sh -f vfat
 mkfs01_ntfs mkfs01.sh -f ntfs
 mkswap01 mkswap01.sh
 lsmod01 lsmod01.sh
+insmod01 insmod01.sh
testcases/commands/insmod/Makefile new file +36 -0
new file mode 100644
index 0000000..69f3ed5
@@ -0,0 +1,36 @@
+#
+#    Copyright (c) 2015 Fujitsu Ltd.
+#    Author:Guangwen Feng <[email protected]>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+ifneq ($(KERNELRELEASE),)
+
+obj-m := test_insmod01.o
+
+else
+
+top_srcdir		?= ../../..
+include $(top_srcdir)/include/mk/testcases.mk
+
+REQ_VERSION_MAJOR       := 2
+REQ_VERSION_PATCH       := 6
+MAKE_TARGETS            := test_insmod01.ko
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= insmod01.sh
+
+include $(top_srcdir)/include/mk/module.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+endif
testcases/commands/insmod/insmod01.sh new file +79 -0

79 lines not on this page · raw message

testcases/commands/insmod/test_insmod01.c new file +35 -0
new file mode 100644
index 0000000..bd7464a
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * Description:
+ * This is a kernel loadable module programme used by insmod01.sh
+ * testcase which inserts this module for test of insmod 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
1.8.4.2
#2 lore raw

PATCH 2/2 commands/insmod: Added new testcase to test insmod(8)

Hi!

testcases/commands/insmod/insmod01.sh line 31

Quoted 9 lines
testcases/commands/insmod/insmod01.sh new file +9 -0
+setup()
+{
+	tst_require_root
+
+	tst_check_cmds rmmod insmod
+
+	if ! [ -e ./test_insmod01.ko ]; then
+		tst_brkm TCONF "'test_insmod01.ko' not found"
+	fi

We should really copy the behavior of tst_module_exist() from C library here, i.e. add a function to test.sh that will return a path to the module in case that it exists. I can write the function if needed.

testcases/commands/insmod/test_insmod01.c

Quoted 1 line
testcases/commands/insmod/test_insmod01.c +0 -0

And I would prefix the module name with ltp_ as well so that it's clear where it came from.

The rest looks good.

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

PATCH 2/2 commands/insmod: Added new testcase to test insmod(8)

Hi!
Thanks for your review!

Quoted 14 lines · Cyril Hrubis

Hi!

testcases/commands/insmod/insmod01.sh line 31

Quoted 9 lines
testcases/commands/insmod/insmod01.sh new file +9 -0
+setup()
+{
+	tst_require_root
+
+	tst_check_cmds rmmod insmod
+
+	if ! [ -e ./test_insmod01.ko ]; then
+		tst_brkm TCONF "'test_insmod01.ko' not found"
+	fi

We should really copy the behavior of tst_module_exist() from C library here, i.e. add a function to test.sh that will return a path to the module in case that it exists. I can write the function if needed.

I got it.
I will add this to test.sh, thanks.

Quoted 5 lines

testcases/commands/insmod/test_insmod01.c

Quoted 2 lines
testcases/commands/insmod/test_insmod01.c +0 -0

And I would prefix the module name with ltp_ as well so that it's clear where it came from.

OK.

Quoted 4 lines

The rest looks good.

#4 lore raw

PATCH v2 1/1 commands/insmod: add new testcase to test insmod(8)

Test the basic functionality of insmod(8) command.

---
 runtest/commands                         |  1 +
 testcases/commands/insmod/Makefile       | 36 ++++++++++++++++
 testcases/commands/insmod/insmod01.sh    | 71 ++++++++++++++++++++++++++++++++
 testcases/commands/insmod/ltp_insmod01.c | 35 ++++++++++++++++
 testcases/lib/test.sh                    | 28 +++++++++++++
 5 files changed, 171 insertions(+)
 create mode 100644 testcases/commands/insmod/Makefile
 create mode 100755 testcases/commands/insmod/insmod01.sh
 create mode 100644 testcases/commands/insmod/ltp_insmod01.c
runtest/commands +1 -0
index db89424..abbbd96 100644
@@ -41,3 +41,4 @@ mkfs01_ntfs mkfs01.sh -f ntfs
 mkswap01 mkswap01.sh
 which01 which01.sh
 lsmod01 lsmod01.sh
+insmod01 insmod01.sh
testcases/commands/insmod/Makefile new file +36 -0
new file mode 100644
index 0000000..e5e68b6
@@ -0,0 +1,36 @@
+#
+#    Copyright (c) 2016 Fujitsu Ltd.
+#    Author:Guangwen Feng <[email protected]>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+ifneq ($(KERNELRELEASE),)
+
+obj-m := ltp_insmod01.o
+
+else
+
+top_srcdir		?= ../../..
+include $(top_srcdir)/include/mk/testcases.mk
+
+REQ_VERSION_MAJOR       := 2
+REQ_VERSION_PATCH       := 6
+MAKE_TARGETS            := ltp_insmod01.ko
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= insmod01.sh
+
+include $(top_srcdir)/include/mk/module.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+endif
testcases/commands/insmod/insmod01.sh new file +71 -0

71 lines not on this page · raw message

testcases/commands/insmod/ltp_insmod01.c new file +35 -0
new file mode 100644
index 0000000..398714e
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * Description:
+ *  This is a kernel loadable module programme used by insmod01.sh
+ *  testcase which inserts this module for test of insmod 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);
testcases/lib/test.sh +28 -0
index 9b652c0..56e1c60 100644
@@ -352,6 +352,34 @@ tst_umount()
 	tst_resm TWARN "Failed to umount($device) after 50 retries"
 }
 
+# Check a module file existence
+# Should be called after tst_tmpdir()
+tst_module_exists()
+{
+	local mod_name="$1"
+
+	if [ -f "$mod_name" ]; then
+		TST_MODPATH="$mod_name"
+		return
+	fi
+
+	local mod_path="$LTPROOT/testcases/bin/$mod_name"
+	if [ -f "$mod_path" ]; then
+		TST_MODPATH="$mod_path"
+		return
+	fi
+
+	if [ -n "$TST_TMPDIR" ]; then
+		mod_path="$TST_TMPDIR/$mod_name"
+		if [ -f "$mod_path" ]; then
+			TST_MODPATH="$mod_path"
+			return
+		fi
+	fi
+
+	tst_brkm TCONF "Failed to find module '$mod_name'"
+}
+
 # Check that test name is set
 if [ -z "$TCID" ]; then
 	tst_brkm TBROK "TCID is not defined"
Signature · 1 line
1.8.4.2
#5 lore raw

PATCH v2 1/1 commands/insmod: add new testcase to test insmod(8)

Hi!

Ping! thanks.

Best Regards,
Guangwen Feng

Quoted 223 lines · Guangwen Feng

Test the basic functionality of insmod(8) command.

---
 runtest/commands                         |  1 +
 testcases/commands/insmod/Makefile       | 36 ++++++++++++++++
 testcases/commands/insmod/insmod01.sh    | 71 ++++++++++++++++++++++++++++++++
 testcases/commands/insmod/ltp_insmod01.c | 35 ++++++++++++++++
 testcases/lib/test.sh                    | 28 +++++++++++++
 5 files changed, 171 insertions(+)
 create mode 100644 testcases/commands/insmod/Makefile
 create mode 100755 testcases/commands/insmod/insmod01.sh
 create mode 100644 testcases/commands/insmod/ltp_insmod01.c
runtest/commands +1 -0
index db89424..abbbd96 100644
@@ -41,3 +41,4 @@ mkfs01_ntfs mkfs01.sh -f ntfs
 mkswap01 mkswap01.sh
 which01 which01.sh
 lsmod01 lsmod01.sh
+insmod01 insmod01.sh
testcases/commands/insmod/Makefile new file +36 -0
new file mode 100644
index 0000000..e5e68b6
@@ -0,0 +1,36 @@
+#
+#    Copyright (c) 2016 Fujitsu Ltd.
+#    Author:Guangwen Feng <[email protected]>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+ifneq ($(KERNELRELEASE),)
+
+obj-m := ltp_insmod01.o
+
+else
+
+top_srcdir		?= ../../..
+include $(top_srcdir)/include/mk/testcases.mk
+
+REQ_VERSION_MAJOR       := 2
+REQ_VERSION_PATCH       := 6
+MAKE_TARGETS            := ltp_insmod01.ko
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= insmod01.sh
+
+include $(top_srcdir)/include/mk/module.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+endif
testcases/commands/insmod/insmod01.sh new file +71 -0
new file mode 100755
index 0000000..f19c068
@@ -0,0 +1,71 @@
+#!/bin/sh
+#
+# Copyright (c) 2016 Fujitsu Ltd.
+# Author: Guangwen Feng <[email protected]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+# the GNU General Public License for more details.
+#
+# Test the basic functionality of insmod command.
+#
+
+TCID=insmod01
+TST_TOTAL=1
+. test.sh
+
+setup()
+{
+	tst_require_root
+
+	tst_check_cmds rmmod insmod
+
+	tst_module_exists ltp_insmod01.ko
+
+	inserted=0
+
+	TST_CLEANUP="cleanup"
+}
+
+cleanup()
+{
+	if [ $inserted -ne 0 ]; then
+		echo "about to rmmod ltp_insmod01"
+		rmmod ltp_insmod01
+		if [ $? -ne 0 ]; then
+			echo "failed to rmmod ltp_insmod01"
+		fi
+	fi
+}
+
+insmod_test()
+{
+	insmod "$TST_MODPATH"
+	if [ $? -ne 0 ]; then
+		tst_resm TFAIL "'insmod' failed."
+		return
+	fi
+	inserted=1
+
+	grep -q ltp_insmod01 /proc/modules
+
+	if [ $? -ne 0 ]; then
+		tst_resm TINFO "ltp_insmod01 not found in /proc/modules"
+		tst_resm TFAIL "'insmod' failed, not expected."
+		return
+	fi
+
+	tst_resm TPASS "'insmod' passed."
+}
+
+setup
+
+insmod_test
+
+tst_exit
testcases/commands/insmod/ltp_insmod01.c new file +35 -0
new file mode 100644
index 0000000..398714e
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * Description:
+ *  This is a kernel loadable module programme used by insmod01.sh
+ *  testcase which inserts this module for test of insmod 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);
testcases/lib/test.sh +28 -0
index 9b652c0..56e1c60 100644
@@ -352,6 +352,34 @@ tst_umount()
 	tst_resm TWARN "Failed to umount($device) after 50 retries"
 }
 
+# Check a module file existence
+# Should be called after tst_tmpdir()
+tst_module_exists()
+{
+	local mod_name="$1"
+
+	if [ -f "$mod_name" ]; then
+		TST_MODPATH="$mod_name"
+		return
+	fi
+
+	local mod_path="$LTPROOT/testcases/bin/$mod_name"
+	if [ -f "$mod_path" ]; then
+		TST_MODPATH="$mod_path"
+		return
+	fi
+
+	if [ -n "$TST_TMPDIR" ]; then
+		mod_path="$TST_TMPDIR/$mod_name"
+		if [ -f "$mod_path" ]; then
+			TST_MODPATH="$mod_path"
+			return
+		fi
+	fi
+
+	tst_brkm TCONF "Failed to find module '$mod_name'"
+}
+
 # Check that test name is set
 if [ -z "$TCID" ]; then
 	tst_brkm TBROK "TCID is not defined"
#6 lore raw

PATCH v2 1/1 commands/insmod: add new testcase to test insmod(8)

In reply to Guangwen Feng

Hi!

Quoted 14 lines
testcases/lib/test.sh +14 -0
+# Check a module file existence
+# Should be called after tst_tmpdir()
+tst_module_exists()
+{
+	local mod_name="$1"
+
+	if [ -f "$mod_name" ]; then
+		TST_MODPATH="$mod_name"
+		return
+	fi
+
+	local mod_path="$LTPROOT/testcases/bin/$mod_name"
+	if [ -f "$mod_path" ]; then
+		TST_MODPATH="$mod_path"

testcases/lib/test.sh tst_umount() · line 378

Quoted 10 lines
testcases/lib/test.sh +10 -0
+		return
+	fi
+
+	if [ -n "$TST_TMPDIR" ]; then
+		mod_path="$TST_TMPDIR/$mod_name"
+		if [ -f "$mod_path" ]; then
+			TST_MODPATH="$mod_path"
+			return
+		fi
+	fi

This is not what the lib/tst_module.c does. It tries test startwd which is recorded before the test does chdir() to the newly created test directory. Otherwise if the test calls tst_tmpdir() the module in the directory the test was started in will not be found. So we have to record the test start working directory in tst_tmpdir() and use it here.

Otherwise it looks good.

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

PATCH v3 1/1 commands/insmod: add new testcase to test insmod(8)

Test the basic functionality of insmod(8) command.

---
 runtest/commands                         |  1 +
 testcases/commands/insmod/Makefile       | 36 ++++++++++++++++
 testcases/commands/insmod/insmod01.sh    | 71 ++++++++++++++++++++++++++++++++
 testcases/commands/insmod/ltp_insmod01.c | 35 ++++++++++++++++
 testcases/lib/test.sh                    | 31 ++++++++++++++
 5 files changed, 174 insertions(+)
 create mode 100644 testcases/commands/insmod/Makefile
 create mode 100755 testcases/commands/insmod/insmod01.sh
 create mode 100644 testcases/commands/insmod/ltp_insmod01.c
runtest/commands +1 -0
index db89424..abbbd96 100644
@@ -41,3 +41,4 @@ mkfs01_ntfs mkfs01.sh -f ntfs
 mkswap01 mkswap01.sh
 which01 which01.sh
 lsmod01 lsmod01.sh
+insmod01 insmod01.sh
testcases/commands/insmod/Makefile new file +36 -0
new file mode 100644
index 0000000..e5e68b6
@@ -0,0 +1,36 @@
+#
+#    Copyright (c) 2016 Fujitsu Ltd.
+#    Author:Guangwen Feng <[email protected]>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+ifneq ($(KERNELRELEASE),)
+
+obj-m := ltp_insmod01.o
+
+else
+
+top_srcdir		?= ../../..
+include $(top_srcdir)/include/mk/testcases.mk
+
+REQ_VERSION_MAJOR       := 2
+REQ_VERSION_PATCH       := 6
+MAKE_TARGETS            := ltp_insmod01.ko
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= insmod01.sh
+
+include $(top_srcdir)/include/mk/module.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+endif
testcases/commands/insmod/insmod01.sh new file +71 -0

71 lines not on this page · raw message

testcases/commands/insmod/ltp_insmod01.c new file +35 -0
new file mode 100644
index 0000000..398714e
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * Description:
+ *  This is a kernel loadable module programme used by insmod01.sh
+ *  testcase which inserts this module for test of insmod 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);
testcases/lib/test.sh +31 -0
index 458bbca..70345e5 100644
@@ -113,6 +113,9 @@ tst_tmpdir()
 	TST_TMPDIR=$(mktemp -d "$TMPDIR/$TCID.XXXXXXXXXX")
 
 	chmod 777 "$TST_TMPDIR"
+
+	TST_STARTWD=$(pwd)
+
 	cd "$TST_TMPDIR"
 }
 
@@ -343,6 +346,34 @@ tst_umount()
 	tst_resm TWARN "Failed to umount($device) after 50 retries"
 }
 
+# Check a module file existence
+# Should be called after tst_tmpdir()
+tst_module_exists()
+{
+	local mod_name="$1"
+
+	if [ -f "$mod_name" ]; then
+		TST_MODPATH="$mod_name"
+		return
+	fi
+
+	local mod_path="$LTPROOT/testcases/bin/$mod_name"
+	if [ -f "$mod_path" ]; then
+		TST_MODPATH="$mod_path"
+		return
+	fi
+
+	if [ -n "$TST_TMPDIR" ]; then
+		mod_path="$TST_STARTWD/$mod_name"
+		if [ -f "$mod_path" ]; then
+			TST_MODPATH="$mod_path"
+			return
+		fi
+	fi
+
+	tst_brkm TCONF "Failed to find module '$mod_name'"
+}
+
 # Check that test name is set
 if [ -z "$TCID" ]; then
 	tst_brkm TBROK "TCID is not defined"
Signature · 1 line
1.8.4.2
#8 lore raw

PATCH v3 1/1 commands/insmod: add new testcase to test insmod(8)

Hi!
I've changed the commit description so that it says that tst_module_exists function was added to the shell library and pushed, thanks.

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

PATCH 1/2 commands/lsmod: Added new testcase to test lsmod(8)

In reply to Guangwen Feng

Hi!
I've moved the verify part to the test function since there is no need to keep it separated for such simple test and simplified the awk part as well. There is no need to use sed if we can do the match in the awk and also awk can read file just fine, no need to use the cat to feed it to stdin.

Pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]