]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: add simple test for list of loaded modules
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 25 Jan 2012 20:16:45 +0000 (18:16 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 26 Jan 2012 18:05:05 +0000 (16:05 -0200)
Makefile.am
testsuite/.gitignore
testsuite/rootfs.tar.xz
testsuite/test-loaded.c [new file with mode: 0644]

index e5f3348042de411782be1574e265cc4589314769..74d1b8c6978b1bac64cf325d6313ceb423fe96a1 100644 (file)
@@ -170,7 +170,7 @@ testsuite_libtestsuite_la_DEPENDENCIES = testsuite/uname.so \
                                         testsuite/rootfs
 testsuite_libtestsuite_la_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
 
-TESTSUITE = testsuite/test-init testsuite/test-testsuite
+TESTSUITE = testsuite/test-init testsuite/test-testsuite testsuite/test-loaded
 check_PROGRAMS = $(TESTSUITE)
 TESTS = $(TESTSUITE)
 
@@ -178,6 +178,9 @@ testsuite_test_init_LDADD = testsuite/libtestsuite.la libkmod/libkmod-private.la
 testsuite_test_init_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
 testsuite_test_testsuite_LDADD = testsuite/libtestsuite.la
 testsuite_test_testsuite_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
+testsuite_test_loaded_LDADD = testsuite/libtestsuite.la libkmod/libkmod-private.la
+testsuite_test_loaded_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
+
 
 DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc
 
index 2cd9099e1a87e790a7d45de093d7c8c6c3f173e2..58cac86aa09188385283c79f79b23e2857d8163d 100644 (file)
@@ -2,6 +2,7 @@
 *.lo
 *.la
 *.so
-test-testsuite
-test-init
 rootfs/
+test-init
+test-loaded
+test-testsuite
index e999c9a508568b79ae480b68cf6ae5c1b6d52e26..091b45a2f0af4d382d6017127dc89bc452efd0df 100644 (file)
Binary files a/testsuite/rootfs.tar.xz and b/testsuite/rootfs.tar.xz differ
diff --git a/testsuite/test-loaded.c b/testsuite/test-loaded.c
new file mode 100644 (file)
index 0000000..d162368
--- /dev/null
@@ -0,0 +1,107 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <errno.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <string.h>
+#include <libkmod.h>
+
+#include "testsuite.h"
+
+static int loaded_1(const struct test *t)
+{
+       struct kmod_ctx *ctx;
+       const char *null_config = NULL;
+       struct kmod_list *list, *itr;
+       int err;
+
+       ctx = kmod_new(NULL, &null_config);
+       if (ctx == NULL)
+               exit(EXIT_FAILURE);
+
+       err = kmod_module_new_from_loaded(ctx, &list);
+       if (err < 0) {
+               fprintf(stderr, "%s\n", strerror(-err));
+               kmod_unref(ctx);
+               exit(EXIT_FAILURE);
+       }
+
+       printf("Module                  Size  Used by\n");
+
+       kmod_list_foreach(itr, list) {
+               struct kmod_module *mod = kmod_module_get_module(itr);
+               const char *name = kmod_module_get_name(mod);
+               int use_count = kmod_module_get_refcnt(mod);
+               long size = kmod_module_get_size(mod);
+               struct kmod_list *holders, *hitr;
+               int first = 1;
+
+               printf("%-19s %8ld  %d ", name, size, use_count);
+               holders = kmod_module_get_holders(mod);
+               kmod_list_foreach(hitr, holders) {
+                       struct kmod_module *hm = kmod_module_get_module(hitr);
+
+                       if (!first)
+                               putchar(',');
+                       else
+                               first = 0;
+
+                       fputs(kmod_module_get_name(hm), stdout);
+                       kmod_module_unref(hm);
+               }
+               putchar('\n');
+               kmod_module_unref_list(holders);
+               kmod_module_unref(mod);
+       }
+       kmod_module_unref_list(list);
+
+       kmod_unref(ctx);
+
+       return EXIT_SUCCESS;
+}
+static const struct test sloaded_1 = {
+       .name = "sloaded_1",
+       .description = "check if list of module is created",
+       .func = loaded_1,
+       .config = {
+               [TC_ROOTFS] = TESTSUITE_ROOTFS "test-loaded/",
+       },
+       .need_spawn = true,
+       .output = {
+               .stdout = TESTSUITE_ROOTFS "test-loaded/correct.txt",
+       },
+};
+
+static const struct test *tests[] = {
+       &sloaded_1,
+       NULL,
+};
+
+int main(int argc, char *argv[])
+{
+       const struct test *t;
+       int arg;
+       size_t i;
+
+       arg = test_init(argc, argv, tests);
+       if (arg == 0)
+               return 0;
+
+       if (arg < argc) {
+               t = test_find(tests, argv[arg]);
+               if (t == NULL) {
+                       fprintf(stderr, "could not find test %s\n", argv[arg]);
+                       exit(EXIT_FAILURE);
+               }
+
+               return test_run(t);
+       }
+
+       for (i = 0; tests[i] != NULL; i++) {
+               if (test_run(tests[i]) != 0)
+                       exit(EXIT_FAILURE);
+       }
+
+       exit(EXIT_SUCCESS);
+}