summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-02-03 13:18:27 -0600
committerDan McGee <dan@archlinux.org>2012-02-06 22:18:08 -0600
commit1708e9ee0f6c8e5d3e51f32a46009d02afcba790 (patch)
tree9e1b50da1e93a423d38894c78cc204912d5e3a39
parent2c6198e19b9fb6c07fddedae9d161354d0ad9900 (diff)
downloadkmod-1708e9ee0f6c8e5d3e51f32a46009d02afcba790.tar.gz
kmod-1708e9ee0f6c8e5d3e51f32a46009d02afcba790.zip
test-conversion: convert test-blacklist to new infrastructure
Add a modprobe.conf with some blacklist entries in a test rootfs, and then ensure our blacklist function actually cuts out the two listed entries (and doesn't cut out the others). Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--Makefile.am5
-rw-r--r--test/test-blacklist.c76
-rw-r--r--testsuite/.gitignore1
-rw-r--r--testsuite/rootfs/test-blacklist/etc/modprobe.d/modprobe.conf2
-rw-r--r--testsuite/test-blacklist.c133
5 files changed, 140 insertions, 77 deletions
diff --git a/Makefile.am b/Makefile.am
index 6c7b238..81bd820 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -163,7 +163,8 @@ testsuite_libtestsuite_la_DEPENDENCIES = testsuite/rootfs \
testsuite_libtestsuite_la_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
TESTSUITE = testsuite/test-init testsuite/test-testsuite testsuite/test-loaded \
- testsuite/test-modinfo testsuite/test-alias testsuite/test-new-module
+ testsuite/test-modinfo testsuite/test-alias testsuite/test-new-module \
+ testsuite/test-blacklist
check_PROGRAMS = $(TESTSUITE)
TESTS = $(TESTSUITE)
@@ -179,6 +180,8 @@ testsuite_test_alias_LDADD = $(TESTSUITE_LDADD)
testsuite_test_alias_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
testsuite_test_new_module_LDADD = $(TESTSUITE_LDADD)
testsuite_test_new_module_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
+testsuite_test_blacklist_LDADD = $(TESTSUITE_LDADD)
+testsuite_test_blacklist_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc
diff --git a/test/test-blacklist.c b/test/test-blacklist.c
deleted file mode 100644
index a53c902..0000000
--- a/test/test-blacklist.c
+++ /dev/null
@@ -1,76 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <errno.h>
-#include <unistd.h>
-#include <inttypes.h>
-#include <string.h>
-#include <libkmod.h>
-
-
-int main(int argc, char *argv[])
-{
- const char *alias;
- struct kmod_ctx *ctx;
- struct kmod_list *list = NULL, *l;
- int err;
-
- printf("libkmod version %s\n", VERSION);
-
- if (argc < 2) {
- fprintf(stderr, "ERR: Provide an alias name\n");
- return EXIT_FAILURE;
- }
-
- alias = argv[1];
-
- ctx = kmod_new(NULL, NULL);
- if (ctx == NULL)
- exit(EXIT_FAILURE);
-
- err = kmod_module_new_from_lookup(ctx, alias, &list);
- if (err < 0)
- goto fail_lookup;
-
- if (list == NULL)
- printf("No module matches '%s'\n", alias);
- else
- printf("Alias: '%s'\nModules matching:\n", alias);
-
- kmod_list_foreach(l, list) {
- struct kmod_module *mod = kmod_module_get_module(l);
- printf("\t%s\n", kmod_module_get_name(mod));
- kmod_module_unref(mod);
- }
-
- if (list != NULL) {
- struct kmod_list *filtered;
- err = kmod_module_get_filtered_blacklist(ctx, list, &filtered);
- if (err < 0) {
- printf("Could not filter: %s\n", strerror(-err));
- goto fail;
- }
- if (filtered == NULL)
- printf("All modules were filtered out!\n");
- else
- printf("Modules remaining after filter:\n");
-
- kmod_list_foreach(l, filtered) {
- struct kmod_module *mod = kmod_module_get_module(l);
- printf("\t%s\n", kmod_module_get_name(mod));
- kmod_module_unref(mod);
- }
- kmod_module_unref_list(filtered);
- }
-
- kmod_module_unref_list(list);
- kmod_unref(ctx);
-
- return EXIT_SUCCESS;
-
-fail:
- kmod_module_unref_list(list);
-fail_lookup:
- kmod_unref(ctx);
- return EXIT_FAILURE;
-}
diff --git a/testsuite/.gitignore b/testsuite/.gitignore
index ec3a77d..f22ca96 100644
--- a/testsuite/.gitignore
+++ b/testsuite/.gitignore
@@ -3,6 +3,7 @@
*.so
/.dirstamp
/test-alias
+/test-blacklist
/test-init
/test-loaded
/test-modinfo
diff --git a/testsuite/rootfs/test-blacklist/etc/modprobe.d/modprobe.conf b/testsuite/rootfs/test-blacklist/etc/modprobe.d/modprobe.conf
new file mode 100644
index 0000000..126612f
--- /dev/null
+++ b/testsuite/rootfs/test-blacklist/etc/modprobe.d/modprobe.conf
@@ -0,0 +1,2 @@
+blacklist floppy
+blacklist pcspkr
diff --git a/testsuite/test-blacklist.c b/testsuite/test-blacklist.c
new file mode 100644
index 0000000..90ea3d7
--- /dev/null
+++ b/testsuite/test-blacklist.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2011-2012 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 <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <errno.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <string.h>
+#include <libkmod.h>
+
+/* good luck bulding a kmod_list outside of the library... makes this blacklist
+ * function rather pointless */
+#include <libkmod-private.h>
+
+/* FIXME: hack, change name so we don't clash */
+#undef ERR
+#include "testsuite.h"
+
+static int blacklist_1(const struct test *t)
+{
+ struct kmod_ctx *ctx;
+ struct kmod_list *list = NULL, *l, *filtered;
+ struct kmod_module *mod;
+ int err;
+ size_t len = 0;
+
+ const char *names[] = { "pcspkr", "pcspkr2", "floppy", "ext4", NULL };
+ const char **name;
+
+ ctx = kmod_new(NULL, NULL);
+ if (ctx == NULL)
+ exit(EXIT_FAILURE);
+
+ for(name = names; *name; name++) {
+ err = kmod_module_new_from_name(ctx, *name, &mod);
+ if (err < 0)
+ goto fail_lookup;
+ list = kmod_list_append(list, mod);
+ }
+
+ err = kmod_module_get_filtered_blacklist(ctx, list, &filtered);
+ if (err < 0) {
+ ERR("Could not filter: %s\n", strerror(-err));
+ goto fail;
+ }
+ if (filtered == NULL) {
+ ERR("All modules were filtered out!\n");
+ goto fail;
+ }
+
+ kmod_list_foreach(l, filtered) {
+ const char *modname;
+ mod = kmod_module_get_module(l);
+ modname = kmod_module_get_name(mod);
+ if (strcmp("pcspkr", modname) == 0 || strcmp("floppy", modname) == 0)
+ goto fail;
+ len++;
+ kmod_module_unref(mod);
+ }
+
+ if (len != 2)
+ goto fail;
+
+ kmod_module_unref_list(filtered);
+ kmod_module_unref_list(list);
+ kmod_unref(ctx);
+
+ return EXIT_SUCCESS;
+
+fail:
+ kmod_module_unref_list(list);
+fail_lookup:
+ kmod_unref(ctx);
+ return EXIT_FAILURE;
+}
+static const struct test sblacklist_1 = {
+ .name = "blacklist_1",
+ .description = "check if modules are correctly blacklisted",
+ .func = blacklist_1,
+ .config = {
+ [TC_ROOTFS] = TESTSUITE_ROOTFS "test-blacklist/",
+ },
+ .need_spawn = true,
+};
+
+static const struct test *tests[] = {
+ &sblacklist_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);
+}