From: Lucas De Marchi Date: Wed, 23 Nov 2011 19:22:09 +0000 (-0200) Subject: Add binary to test rmmod feature X-Git-Tag: v1~199 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eee1345cf24fcd21efcef907aec2ded4cca98874;p=platform%2Fupstream%2Fkmod.git Add binary to test rmmod feature It doesn't run with `make check' since o It's dangerous o It needs to be run as root o It needs an argument, otherwise it removes the first module with use_count==0 --- diff --git a/Makefile.am b/Makefile.am index 929de86..a55a03a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,9 +45,13 @@ pkgconfig_DATA = libkmod/libkmod.pc TESTS = test/test-init test/test-loaded -check_PROGRAMS = test/test-init test/test-loaded +check_PROGRAMS = test/test-init test/test-loaded test/test-rmmod test_test_init_SOURCES = test/test-init.c test_test_init_LDADD = libkmod/libkmod.la test_test_loaded_SOURCES = test/test-loaded.c test_test_loaded_LDADD = libkmod/libkmod.la + +noinst_PROGRAMS = test/test-rmmod $(check_PROGRAMS) +test_test_rmmod_SOURCES = test/test-rmmod.c +test_test_rmmod_LDADD = libkmod/libkmod.la diff --git a/test/.gitignore b/test/.gitignore index 20b56b7..1cbe6b8 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,3 +1,4 @@ .dirstamp test-init test-loaded +test-rmmod diff --git a/test/test-rmmod.c b/test/test-rmmod.c new file mode 100644 index 0000000..759743e --- /dev/null +++ b/test/test-rmmod.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + const char *modname = NULL; + struct kmod_ctx *ctx; + struct kmod_loaded *mod; + struct kmod_list *list, *itr; + int err; + + if (argc == 2) + modname = argv[1]; + + ctx = kmod_new(); + if (ctx == NULL) + exit(EXIT_FAILURE); + + printf("libkmod version %s\n", VERSION); + + err = kmod_loaded_new(ctx, &mod); + if (err < 0) + exit(EXIT_FAILURE); + + err = kmod_loaded_get_list(mod, &list); + if (err < 0) { + fprintf(stderr, "%s\n", strerror(-err)); + exit(EXIT_FAILURE); + } + + kmod_list_foreach(itr, list) { + const char *name; + int use_count; + + kmod_loaded_get_module_info(itr, &name, NULL, &use_count, + NULL, NULL); + + if ((modname && !strcmp(modname, name)) || + (modname == NULL && use_count == 0)) { + printf("Trying to remove '%s'\n", name); + kmod_loaded_remove_module(mod, itr, 0); + break; + } + } + + kmod_loaded_unref(mod); + kmod_unref(ctx); + + return EXIT_SUCCESS; +}