* [PATCH 1/3] testsuite: remove .gitignore files when populating rootfs
@ 2015-03-05 16:06 Caio Marcelo de Oliveira Filho
2015-03-05 16:06 ` [PATCH 2/3] testsuite: update README Caio Marcelo de Oliveira Filho
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-03-05 16:06 UTC (permalink / raw)
To: linux-modules
Usually this file is added to keep a directory existing in the
repository but without any real content. In rootfs this can be
problematic if a directory will have all its files inspected. This
happens for kmod_module_get_holders().
Side-note: the 'test-loaded.c' is hit by this problem but doesn't
"notice" because the invalid module returned by get_holders() is not
checked. The modules in its loop are only used to get the name and
generate an output, and NULL was a valid value to generate the name.
---
Makefile.am | 1 +
1 file changed, 1 insertion(+)
diff --git a/Makefile.am b/Makefile.am
index 896ae63..d9da17d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -216,6 +216,7 @@ ROOTFS_PRISTINE = $(top_srcdir)/testsuite/rootfs-pristine
CREATE_ROOTFS = $(AM_V_GEN) ( $(RM) -rf $(ROOTFS) && mkdir -p $(dir $(ROOTFS)) && \
cp -r $(ROOTFS_PRISTINE) $(ROOTFS) && \
find $(ROOTFS) -type d -exec chmod +w {} \; && \
+ find $(ROOTFS) -type f -name .gitignore -exec rm -f {} \; && \
$(top_srcdir)/testsuite/populate-modules.sh \
$(MODULE_PLAYGROUND) $(ROOTFS) ) && \
touch testsuite/stamp-rootfs
--
2.3.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] testsuite: update README
2015-03-05 16:06 [PATCH 1/3] testsuite: remove .gitignore files when populating rootfs Caio Marcelo de Oliveira Filho
@ 2015-03-05 16:06 ` Caio Marcelo de Oliveira Filho
2015-03-05 16:06 ` [PATCH 3/3] tools: add basic versions of insert and remove Caio Marcelo de Oliveira Filho
2015-03-06 3:24 ` [PATCH 1/3] testsuite: remove .gitignore files when populating rootfs Lucas De Marchi
2 siblings, 0 replies; 6+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-03-05 16:06 UTC (permalink / raw)
To: linux-modules
---
testsuite/README | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/testsuite/README b/testsuite/README
index d5843bf..6efc61e 100644
--- a/testsuite/README
+++ b/testsuite/README
@@ -33,7 +33,7 @@ pay attention when writing a test:
3 - If you want testsuite to compare the stdout/stderr of your tests in order
to check if it worked or not, fill in output.{stderr,stdout} the file with
- the expected output. Bare in mind the same file is used for all
+ the expected output. Bear in mind the same file is used for all
architectures, so don't print arch-dependent content if you are comparing
the output.
@@ -49,8 +49,10 @@ pay attention when writing a test:
6 - expected_fail: if that test is expected to fail, i.e. the return code is
expected not to be 0.
-7 - If you added files to the rootfs, be sure to compact it back to
- rootfs.tar.xz before sending patches: use 'make testsuite-pack-rootfs'
+7 - The rootfs is populated by copying the entire contents of rootfs-pristine
+ then running populate-modules.sh to copy generated modules from
+ module-playground. Update the latter script to include any modules your
+ test need.
8 - Tests can be run individually, outside of 'make check'. strace and gdb work
too, as long as you tell them to operate on child process.
--
2.3.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] tools: add basic versions of insert and remove
2015-03-05 16:06 [PATCH 1/3] testsuite: remove .gitignore files when populating rootfs Caio Marcelo de Oliveira Filho
2015-03-05 16:06 ` [PATCH 2/3] testsuite: update README Caio Marcelo de Oliveira Filho
@ 2015-03-05 16:06 ` Caio Marcelo de Oliveira Filho
2015-03-06 3:23 ` Lucas De Marchi
2015-03-06 3:24 ` [PATCH 1/3] testsuite: remove .gitignore files when populating rootfs Lucas De Marchi
2 siblings, 1 reply; 6+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-03-05 16:06 UTC (permalink / raw)
To: linux-modules
---
Makefile.am | 7 +-
testsuite/.gitignore | 3 +
testsuite/populate-modules.sh | 2 +
.../insert/lib/modules/4.4.4/modules.alias | 1 +
.../insert/lib/modules/4.4.4/modules.alias.bin | Bin 0 -> 12 bytes
.../insert/lib/modules/4.4.4/modules.builtin | 0
.../insert/lib/modules/4.4.4/modules.builtin.bin | Bin 0 -> 12 bytes
.../insert/lib/modules/4.4.4/modules.dep | 1 +
.../insert/lib/modules/4.4.4/modules.dep.bin | Bin 0 -> 58 bytes
.../insert/lib/modules/4.4.4/modules.devname | 1 +
.../insert/lib/modules/4.4.4/modules.order | 0
.../insert/lib/modules/4.4.4/modules.softdep | 1 +
.../insert/lib/modules/4.4.4/modules.symbols | 1 +
.../insert/lib/modules/4.4.4/modules.symbols.bin | Bin 0 -> 12 bytes
.../remove/lib/modules/4.4.4/modules.alias | 1 +
.../remove/lib/modules/4.4.4/modules.alias.bin | Bin 0 -> 12 bytes
.../remove/lib/modules/4.4.4/modules.builtin | 0
.../remove/lib/modules/4.4.4/modules.builtin.bin | Bin 0 -> 12 bytes
.../remove/lib/modules/4.4.4/modules.dep | 1 +
.../remove/lib/modules/4.4.4/modules.dep.bin | Bin 0 -> 58 bytes
.../remove/lib/modules/4.4.4/modules.devname | 1 +
.../remove/lib/modules/4.4.4/modules.order | 0
.../remove/lib/modules/4.4.4/modules.softdep | 1 +
.../remove/lib/modules/4.4.4/modules.symbols | 1 +
.../remove/lib/modules/4.4.4/modules.symbols.bin | Bin 0 -> 12 bytes
.../sys/module/mod_simple/holders/.gitignore | 0
.../remove/sys/module/mod_simple/initstate | 1 +
.../test-tools/remove/sys/module/mod_simple/refcnt | 1 +
testsuite/test-tools.c | 54 ++++++++
tools/insert.c | 126 +++++++++++++++++
tools/kmod.c | 2 +
tools/kmod.h | 2 +
tools/remove.c | 149 +++++++++++++++++++++
33 files changed, 356 insertions(+), 1 deletion(-)
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.alias
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.alias.bin
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.builtin
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.builtin.bin
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.dep
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.dep.bin
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.devname
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.order
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.softdep
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.symbols
create mode 100644 testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.symbols.bin
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.alias
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.alias.bin
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.builtin
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.builtin.bin
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.dep
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.dep.bin
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.devname
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.order
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.softdep
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.symbols
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.symbols.bin
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/holders/.gitignore
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/initstate
create mode 100644 testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/refcnt
create mode 100644 testsuite/test-tools.c
create mode 100644 tools/insert.c
create mode 100644 tools/remove.c
diff --git a/Makefile.am b/Makefile.am
index d9da17d..caf18b6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -126,6 +126,8 @@ tools_kmod_SOURCES = \
tools/rmmod.c tools/insmod.c \
tools/modinfo.c tools/modprobe.c \
tools/depmod.c tools/log.h tools/log.c \
+ tools/insert.c \
+ tools/remove.c \
tools/static-nodes.c
tools_kmod_LDADD = \
shared/libshared.la \
@@ -315,7 +317,8 @@ TESTSUITE = \
testsuite/test-modinfo testsuite/test-util testsuite/test-new-module \
testsuite/test-modprobe testsuite/test-blacklist \
testsuite/test-dependencies testsuite/test-depmod \
- testsuite/test-list
+ testsuite/test-list \
+ testsuite/test-tools
check_PROGRAMS = $(TESTSUITE)
TESTS = $(TESTSUITE)
@@ -355,6 +358,8 @@ testsuite_test_depmod_LDADD = $(TESTSUITE_LDADD)
testsuite_test_depmod_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
testsuite_test_list_LDADD = $(TESTSUITE_LDADD)
testsuite_test_list_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
+testsuite_test_tools_LDADD = $(TESTSUITE_LDADD)
+testsuite_test_tools_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
testsuite-distclean:
$(RM) -r $(ROOTFS)
diff --git a/testsuite/.gitignore b/testsuite/.gitignore
index 09f231c..2b71a47 100644
--- a/testsuite/.gitignore
+++ b/testsuite/.gitignore
@@ -17,6 +17,7 @@
/test-modprobe
/test-hash
/test-list
+/test-tools
/rootfs
/stamp-rootfs
/test-strbuf.log
@@ -49,3 +50,5 @@
/test-testsuite.trs
/test-list.log
/test-list.trs
+/test-tools.log
+/test-tools.trs
diff --git a/testsuite/populate-modules.sh b/testsuite/populate-modules.sh
index 43fb834..409a6de 100755
--- a/testsuite/populate-modules.sh
+++ b/testsuite/populate-modules.sh
@@ -42,6 +42,8 @@ map=(
["test-modinfo/mod-simple-sparc64.ko"]="mod-simple-sparc64.ko"
["test-modinfo/mod-simple-sha1.ko"]="mod-simple.ko"
["test-modinfo/mod-simple-sha256.ko"]="mod-simple.ko"
+ ["test-tools/insert/lib/modules/4.4.4/kernel/"]="mod-simple.ko"
+ ["test-tools/remove/lib/modules/4.4.4/kernel/"]="mod-simple.ko"
)
gzip_array=(
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.alias b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.alias
new file mode 100644
index 0000000..ba76e18
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.alias
@@ -0,0 +1 @@
+# Aliases extracted from modules themselves.
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.alias.bin b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.alias.bin
new file mode 100644
index 0000000000000000000000000000000000000000..7075435f6268c4d815aec093d61e26647666ba76
GIT binary patch
literal 12
TcmdnM{w17&iGh)Ufq@4A6;A>Z
literal 0
HcmV?d00001
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.builtin b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.builtin
new file mode 100644
index 0000000..e69de29
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.builtin.bin b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.builtin.bin
new file mode 100644
index 0000000000000000000000000000000000000000..7075435f6268c4d815aec093d61e26647666ba76
GIT binary patch
literal 12
TcmdnM{w17&iGh)Ufq@4A6;A>Z
literal 0
HcmV?d00001
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.dep b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.dep
new file mode 100644
index 0000000..5476653
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.dep
@@ -0,0 +1 @@
+kernel/mod-simple.ko:
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.dep.bin b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.dep.bin
new file mode 100644
index 0000000000000000000000000000000000000000..b09a85432309c43f99500d6cc3473bcb1ef0a80e
GIT binary patch
literal 58
zcmdnM{w17&iGfjpfx#p{CB8T_w;(5#0SFjDM0RRXUTThhZhnd`L`E+=--;nO_W%O}
F4*<8l52gSB
literal 0
HcmV?d00001
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.devname b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.devname
new file mode 100644
index 0000000..58f6d6d
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.devname
@@ -0,0 +1 @@
+# Device nodes to trigger on-demand module loading.
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.order b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.order
new file mode 100644
index 0000000..e69de29
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.softdep b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.softdep
new file mode 100644
index 0000000..5554ccc
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.softdep
@@ -0,0 +1 @@
+# Soft dependencies extracted from modules themselves.
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.symbols b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.symbols
new file mode 100644
index 0000000..618c345
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.symbols
@@ -0,0 +1 @@
+# Aliases for symbols, used by symbol_request().
diff --git a/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.symbols.bin b/testsuite/rootfs-pristine/test-tools/insert/lib/modules/4.4.4/modules.symbols.bin
new file mode 100644
index 0000000000000000000000000000000000000000..7075435f6268c4d815aec093d61e26647666ba76
GIT binary patch
literal 12
TcmdnM{w17&iGh)Ufq@4A6;A>Z
literal 0
HcmV?d00001
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.alias b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.alias
new file mode 100644
index 0000000..ba76e18
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.alias
@@ -0,0 +1 @@
+# Aliases extracted from modules themselves.
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.alias.bin b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.alias.bin
new file mode 100644
index 0000000000000000000000000000000000000000..7075435f6268c4d815aec093d61e26647666ba76
GIT binary patch
literal 12
TcmdnM{w17&iGh)Ufq@4A6;A>Z
literal 0
HcmV?d00001
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.builtin b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.builtin
new file mode 100644
index 0000000..e69de29
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.builtin.bin b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.builtin.bin
new file mode 100644
index 0000000000000000000000000000000000000000..7075435f6268c4d815aec093d61e26647666ba76
GIT binary patch
literal 12
TcmdnM{w17&iGh)Ufq@4A6;A>Z
literal 0
HcmV?d00001
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.dep b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.dep
new file mode 100644
index 0000000..5476653
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.dep
@@ -0,0 +1 @@
+kernel/mod-simple.ko:
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.dep.bin b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.dep.bin
new file mode 100644
index 0000000000000000000000000000000000000000..b09a85432309c43f99500d6cc3473bcb1ef0a80e
GIT binary patch
literal 58
zcmdnM{w17&iGfjpfx#p{CB8T_w;(5#0SFjDM0RRXUTThhZhnd`L`E+=--;nO_W%O}
F4*<8l52gSB
literal 0
HcmV?d00001
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.devname b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.devname
new file mode 100644
index 0000000..58f6d6d
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.devname
@@ -0,0 +1 @@
+# Device nodes to trigger on-demand module loading.
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.order b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.order
new file mode 100644
index 0000000..e69de29
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.softdep b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.softdep
new file mode 100644
index 0000000..5554ccc
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.softdep
@@ -0,0 +1 @@
+# Soft dependencies extracted from modules themselves.
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.symbols b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.symbols
new file mode 100644
index 0000000..618c345
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.symbols
@@ -0,0 +1 @@
+# Aliases for symbols, used by symbol_request().
diff --git a/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.symbols.bin b/testsuite/rootfs-pristine/test-tools/remove/lib/modules/4.4.4/modules.symbols.bin
new file mode 100644
index 0000000000000000000000000000000000000000..7075435f6268c4d815aec093d61e26647666ba76
GIT binary patch
literal 12
TcmdnM{w17&iGh)Ufq@4A6;A>Z
literal 0
HcmV?d00001
diff --git a/testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/holders/.gitignore b/testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/holders/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/initstate b/testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/initstate
new file mode 100644
index 0000000..e23fe64
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/initstate
@@ -0,0 +1 @@
+live
diff --git a/testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/refcnt b/testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/refcnt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-tools/remove/sys/module/mod_simple/refcnt
@@ -0,0 +1 @@
+0
diff --git a/testsuite/test-tools.c b/testsuite/test-tools.c
new file mode 100644
index 0000000..66a78a1
--- /dev/null
+++ b/testsuite/test-tools.c
@@ -0,0 +1,54 @@
+#include <errno.h>
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "testsuite.h"
+
+static noreturn int kmod_tool_insert(const struct test *t)
+{
+ const char *progname = ABS_TOP_BUILDDIR "/tools/kmod";
+ const char *const args[] = {
+ progname,
+ "insert", "mod-simple",
+ NULL,
+ };
+
+ test_spawn_prog(progname, args);
+ exit(EXIT_FAILURE);
+}
+DEFINE_TEST(kmod_tool_insert,
+ .description = "check kmod insert",
+ .config = {
+ [TC_UNAME_R] = "4.4.4",
+ [TC_ROOTFS] = TESTSUITE_ROOTFS "test-tools/insert",
+ [TC_INIT_MODULE_RETCODES] = "",
+ },
+ .modules_loaded = "mod-simple",
+ );
+
+static noreturn int kmod_tool_remove(const struct test *t)
+{
+ const char *progname = ABS_TOP_BUILDDIR "/tools/kmod";
+ const char *const args[] = {
+ progname,
+ "remove", "mod-simple",
+ NULL,
+ };
+
+ test_spawn_prog(progname, args);
+ exit(EXIT_FAILURE);
+}
+DEFINE_TEST(kmod_tool_remove,
+ .description = "check kmod remove",
+ .config = {
+ [TC_UNAME_R] = "4.4.4",
+ [TC_ROOTFS] = TESTSUITE_ROOTFS "test-tools/remove",
+ [TC_DELETE_MODULE_RETCODES] = "",
+ },
+ );
+
+TESTSUITE_MAIN();
diff --git a/tools/insert.c b/tools/insert.c
new file mode 100644
index 0000000..cc5bbc6
--- /dev/null
+++ b/tools/insert.c
@@ -0,0 +1,126 @@
+/*
+ * kmod-insert - insert a module into the kernel.
+ *
+ * Copyright (C) 2011-2013 ProFUSION embedded systems
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <errno.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libkmod/libkmod.h>
+
+#include "kmod.h"
+
+static const char cmdopts_s[] = "h";
+static const struct option cmdopts[] = {
+ {"help", no_argument, 0, 'h'},
+ {NULL, 0, 0, 0}
+};
+
+static void help(void)
+{
+ printf("Usage:\n"
+ "\t%s insert [options] module\n"
+ "Options:\n"
+ "\t-h, --help show this help\n",
+ program_invocation_short_name);
+}
+
+static const char *mod_strerror(int err)
+{
+ switch (err) {
+ case KMOD_PROBE_APPLY_BLACKLIST:
+ return "Module is blacklisted";
+ case -EEXIST:
+ return "Module already in kernel";
+ case -ENOENT:
+ return "Unknown symbol in module or unknown parameter (see dmesg)";
+ default:
+ return strerror(-err);
+ }
+}
+
+static int do_insert(int argc, char *argv[])
+{
+ struct kmod_ctx *ctx;
+ struct kmod_list *list = NULL, *l;
+ const char *name;
+ int err, result = EXIT_FAILURE;
+
+ for (;;) {
+ int c, idx = 0;
+ c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx);
+ if (c == -1)
+ break;
+ switch (c) {
+ case 'h':
+ help();
+ return EXIT_SUCCESS;
+ default:
+ ERR("Unexpected getopt_long() value '%c'.\n", c);
+ return EXIT_FAILURE;
+ }
+ }
+
+ if (optind >= argc) {
+ ERR("Missing module name\n");
+ return EXIT_FAILURE;
+ }
+
+ ctx = kmod_new(NULL, NULL);
+ if (!ctx) {
+ ERR("kmod_new() failed!\n");
+ return EXIT_FAILURE;
+ }
+
+ name = argv[optind];
+ err = kmod_module_new_from_lookup(ctx, name, &list);
+ if (err < 0) {
+ ERR("Could not lookup module matching '%s': %s\n", name, strerror(-err));
+ goto end;
+ }
+
+ if (list == NULL) {
+ ERR("No module matches '%s'\n", name);
+ goto end;
+ }
+
+ kmod_list_foreach(l, list) {
+ struct kmod_module *mod = kmod_module_get_module(l);
+
+ err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
+ if (err != 0)
+ ERR("Could not insert '%s': %s\n", kmod_module_get_name(mod), mod_strerror(err));
+
+ kmod_module_unref(mod);
+ }
+
+ if (err == 0)
+ result = EXIT_SUCCESS;
+
+ kmod_module_unref_list(list);
+end:
+ kmod_unref(ctx);
+ return result;
+}
+
+const struct kmod_cmd kmod_cmd_insert = {
+ .name = "insert",
+ .cmd = do_insert,
+ .help = "insert a module into the kernel",
+};
diff --git a/tools/kmod.c b/tools/kmod.c
index 8ae1d86..5ebe70a 100644
--- a/tools/kmod.c
+++ b/tools/kmod.c
@@ -40,7 +40,9 @@ static const struct kmod_cmd kmod_cmd_help;
static const struct kmod_cmd *kmod_cmds[] = {
&kmod_cmd_help,
+ &kmod_cmd_insert,
&kmod_cmd_list,
+ &kmod_cmd_remove,
&kmod_cmd_static_nodes,
};
diff --git a/tools/kmod.h b/tools/kmod.h
index 50adda4..1770786 100644
--- a/tools/kmod.h
+++ b/tools/kmod.h
@@ -34,7 +34,9 @@ extern const struct kmod_cmd kmod_cmd_compat_modinfo;
extern const struct kmod_cmd kmod_cmd_compat_modprobe;
extern const struct kmod_cmd kmod_cmd_compat_depmod;
+extern const struct kmod_cmd kmod_cmd_insert;
extern const struct kmod_cmd kmod_cmd_list;
extern const struct kmod_cmd kmod_cmd_static_nodes;
+extern const struct kmod_cmd kmod_cmd_remove;
#include "log.h"
diff --git a/tools/remove.c b/tools/remove.c
new file mode 100644
index 0000000..e3c1550
--- /dev/null
+++ b/tools/remove.c
@@ -0,0 +1,149 @@
+/*
+ * kmod-rmmod - remove modules from the kernel.
+ *
+ * Copyright (C) 2011-2013 ProFUSION embedded systems
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <errno.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libkmod/libkmod.h>
+
+#include "kmod.h"
+
+static const char cmdopts_s[] = "h";
+static const struct option cmdopts[] = {
+ {"help", no_argument, 0, 'h'},
+ {NULL, 0, 0, 0}
+};
+
+static void help(void)
+{
+ printf("Usage:\n"
+ "\t%s remove [options] module\n"
+ "Options:\n"
+ "\t-h, --help show this help\n",
+ program_invocation_short_name);
+}
+
+static int check_module_inuse(struct kmod_module *mod) {
+ struct kmod_list *holders;
+ int state;
+
+ state = kmod_module_get_initstate(mod);
+
+ if (state == KMOD_MODULE_BUILTIN) {
+ ERR("Module %s is builtin.\n", kmod_module_get_name(mod));
+ return -ENOENT;
+ } else if (state < 0) {
+ ERR("Module %s is not currently loaded\n",
+ kmod_module_get_name(mod));
+ return -ENOENT;
+ }
+
+ holders = kmod_module_get_holders(mod);
+ if (holders != NULL) {
+ struct kmod_list *itr;
+
+ ERR("Module %s is in use by:", kmod_module_get_name(mod));
+
+ kmod_list_foreach(itr, holders) {
+ struct kmod_module *hm = kmod_module_get_module(itr);
+ fprintf(stderr, " %s", kmod_module_get_name(hm));
+ kmod_module_unref(hm);
+ }
+ fputc('\n', stderr);
+
+ kmod_module_unref_list(holders);
+ return -EBUSY;
+ }
+
+ if (kmod_module_get_refcnt(mod) != 0) {
+ ERR("Module %s is in use\n", kmod_module_get_name(mod));
+ return -EBUSY;
+ }
+
+ return 0;
+}
+
+static int do_remove(int argc, char *argv[])
+{
+ struct kmod_ctx *ctx;
+ struct kmod_module *mod;
+ const char *name;
+ int err, r = EXIT_FAILURE;
+
+ for (;;) {
+ int c, idx =0;
+ c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx);
+ if (c == -1)
+ break;
+ switch (c) {
+ case 'h':
+ help();
+ return EXIT_SUCCESS;
+
+ default:
+ ERR("Unexpected getopt_long() value '%c'.\n", c);
+ return EXIT_FAILURE;
+ }
+ }
+
+ if (optind >= argc) {
+ ERR("Missing module name\n");
+ return EXIT_FAILURE;
+ }
+
+ ctx = kmod_new(NULL, NULL);
+ if (!ctx) {
+ ERR("kmod_new() failed!\n");
+ return EXIT_FAILURE;
+ }
+
+ name = argv[optind];
+ err = kmod_module_new_from_name(ctx, name, &mod);
+ if (err < 0) {
+ ERR("Could not remove module %s: %s\n", name, strerror(-err));
+ goto end;
+ }
+
+ err = check_module_inuse(mod);
+ if (err < 0)
+ goto unref;
+
+ err = kmod_module_remove_module(mod, 0);
+ if (err < 0)
+ goto unref;
+
+ r = EXIT_SUCCESS;
+
+unref:
+ kmod_module_unref(mod);
+
+end:
+ kmod_unref(ctx);
+ if (err)
+ ERR("Could not remove module %s: %s\n", name, strerror(-err));
+ return r;
+}
+
+const struct kmod_cmd kmod_cmd_remove = {
+ .name = "remove",
+ .cmd = do_remove,
+ .help = "remove module from kernel",
+};
--
2.3.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] tools: add basic versions of insert and remove
2015-03-05 16:06 ` [PATCH 3/3] tools: add basic versions of insert and remove Caio Marcelo de Oliveira Filho
@ 2015-03-06 3:23 ` Lucas De Marchi
2015-03-07 13:39 ` Caio Marcelo de Oliveira Filho
0 siblings, 1 reply; 6+ messages in thread
From: Lucas De Marchi @ 2015-03-06 3:23 UTC (permalink / raw)
To: Caio Marcelo de Oliveira Filho; +Cc: linux-modules
Overall it's nice, but I have some comments on this one. See below
On Thu, Mar 5, 2015 at 1:06 PM, Caio Marcelo de Oliveira Filho
<caio.oliveira@intel.com> wrote:
> diff --git a/testsuite/test-tools.c b/testsuite/test-tools.c
> new file mode 100644
> index 0000000..66a78a1
> --- /dev/null
> +++ b/testsuite/test-tools.c
> @@ -0,0 +1,54 @@
> +#include <errno.h>
> +#include <inttypes.h>
> +#include <stddef.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +
> +#include "testsuite.h"
> +
> +static noreturn int kmod_tool_insert(const struct test *t)
> +{
> + const char *progname = ABS_TOP_BUILDDIR "/tools/kmod";
> + const char *const args[] = {
> + progname,
> + "insert", "mod-simple",
> + NULL,
> + };
> +
> + test_spawn_prog(progname, args);
> + exit(EXIT_FAILURE);
> +}
> +DEFINE_TEST(kmod_tool_insert,
> + .description = "check kmod insert",
> + .config = {
> + [TC_UNAME_R] = "4.4.4",
> + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-tools/insert",
> + [TC_INIT_MODULE_RETCODES] = "",
are these and other similar ones correct? why do you need to set it
to an empty string?
> diff --git a/tools/insert.c b/tools/insert.c
> new file mode 100644
> index 0000000..cc5bbc6
> --- /dev/null
> +++ b/tools/insert.c
> @@ -0,0 +1,126 @@
> +/*
> + * kmod-insert - insert a module into the kernel.
> + *
> + * Copyright (C) 2011-2013 ProFUSION embedded systems
Add a Copyright line here (and in remove.c as well). These are more
than just copies.
> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <errno.h>
> +#include <getopt.h>
> +#include <stdlib.h>
> +#include <string.h>
> +
> +#include <libkmod/libkmod.h>
> +
> +#include "kmod.h"
> +
> +static const char cmdopts_s[] = "h";
> +static const struct option cmdopts[] = {
> + {"help", no_argument, 0, 'h'},
> + {NULL, 0, 0, 0}
use empty initializers: { }
> +static int do_insert(int argc, char *argv[])
> +{
[ ... ]
> + kmod_list_foreach(l, list) {
> + struct kmod_module *mod = kmod_module_get_module(l);
> +
> + err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
> + if (err != 0)
> + ERR("Could not insert '%s': %s\n", kmod_module_get_name(mod), mod_strerror(err));
> +
> + kmod_module_unref(mod);
missing 1 unref() in the error path. Just reorder the error check with
the unref() and you'll be fine.
> diff --git a/tools/remove.c b/tools/remove.c
> new file mode 100644
> index 0000000..e3c1550
> --- /dev/null
> +++ b/tools/remove.c
> @@ -0,0 +1,149 @@
> +/*
> + * kmod-rmmod - remove modules from the kernel.
kmod-remove
thanks.
--
Lucas De Marchi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] testsuite: remove .gitignore files when populating rootfs
2015-03-05 16:06 [PATCH 1/3] testsuite: remove .gitignore files when populating rootfs Caio Marcelo de Oliveira Filho
2015-03-05 16:06 ` [PATCH 2/3] testsuite: update README Caio Marcelo de Oliveira Filho
2015-03-05 16:06 ` [PATCH 3/3] tools: add basic versions of insert and remove Caio Marcelo de Oliveira Filho
@ 2015-03-06 3:24 ` Lucas De Marchi
2 siblings, 0 replies; 6+ messages in thread
From: Lucas De Marchi @ 2015-03-06 3:24 UTC (permalink / raw)
To: Caio Marcelo de Oliveira Filho; +Cc: linux-modules
On Thu, Mar 5, 2015 at 1:06 PM, Caio Marcelo de Oliveira Filho
<caio.oliveira@intel.com> wrote:
> Usually this file is added to keep a directory existing in the
> repository but without any real content. In rootfs this can be
> problematic if a directory will have all its files inspected. This
> happens for kmod_module_get_holders().
>
> Side-note: the 'test-loaded.c' is hit by this problem but doesn't
> "notice" because the invalid module returned by get_holders() is not
> checked. The modules in its loop are only used to get the name and
> generate an output, and NULL was a valid value to generate the name.
> ---
applied this and the second patch... some comments on the third one.
--
Lucas De Marchi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] tools: add basic versions of insert and remove
2015-03-06 3:23 ` Lucas De Marchi
@ 2015-03-07 13:39 ` Caio Marcelo de Oliveira Filho
0 siblings, 0 replies; 6+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-03-07 13:39 UTC (permalink / raw)
To: Lucas De Marchi; +Cc: linux-modules
Thanks! Pushed a new version of the patch fixing the minor issues.
On Fri, Mar 06, 2015 at 12:23:29AM -0300, Lucas De Marchi wrote:
> Overall it's nice, but I have some comments on this one. See below
> > +DEFINE_TEST(kmod_tool_insert,
> > + .description = "check kmod insert",
> > + .config = {
> > + [TC_UNAME_R] = "4.4.4",
> > + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-tools/insert",
> > + [TC_INIT_MODULE_RETCODES] = "",
>
> are these and other similar ones correct? why do you need to set it
> to an empty string?
If TC_INIT_MODULE_RETCODES is NULL, the preload for init_module won't
be loaded, so we need it set.
When set, it will automatically succeed loading any non-builtin
modules, except those mentioned in the string, that will succeed or
not depending on the error code.
Same approach is taken by TC_DELETE_MODULE_RETCODES.
> > + kmod_list_foreach(l, list) {
> > + struct kmod_module *mod = kmod_module_get_module(l);
> > +
> > + err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
> > + if (err != 0)
> > + ERR("Could not insert '%s': %s\n", kmod_module_get_name(mod), mod_strerror(err));
> > +
> > + kmod_module_unref(mod);
>
> missing 1 unref() in the error path. Just reorder the error check with
> the unref() and you'll be fine.
ERR() doesn't return or break, each get_module() will have a
corresponding unref() call.
I've ended up rewriting the return code handling to ensure that if one
of the insertions fail, return code will be EXIT_FAILURE.
Cheers,
Caio
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-03-07 13:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05 16:06 [PATCH 1/3] testsuite: remove .gitignore files when populating rootfs Caio Marcelo de Oliveira Filho
2015-03-05 16:06 ` [PATCH 2/3] testsuite: update README Caio Marcelo de Oliveira Filho
2015-03-05 16:06 ` [PATCH 3/3] tools: add basic versions of insert and remove Caio Marcelo de Oliveira Filho
2015-03-06 3:23 ` Lucas De Marchi
2015-03-07 13:39 ` Caio Marcelo de Oliveira Filho
2015-03-06 3:24 ` [PATCH 1/3] testsuite: remove .gitignore files when populating rootfs Lucas De Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).