]> git.ipfire.org Git - thirdparty/kmod.git/blame - testsuite/test-blacklist.c
testsuite: remove now unused array of tests
[thirdparty/kmod.git] / testsuite / test-blacklist.c
CommitLineData
bcca1b95 1/*
e6b0e49b 2 * Copyright (C) 2011-2013 ProFUSION embedded systems
bcca1b95 3 *
e1b1ab24
LDM
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
bcca1b95
DM
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e1b1ab24
LDM
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
bcca1b95 13 *
e1b1ab24
LDM
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
bcca1b95
DM
17 */
18
bcca1b95 19#include <errno.h>
bcca1b95 20#include <inttypes.h>
c2e4286b
LDM
21#include <stddef.h>
22#include <stdio.h>
23#include <stdlib.h>
bcca1b95 24#include <string.h>
c2e4286b
LDM
25#include <unistd.h>
26
bcca1b95
DM
27#include <libkmod.h>
28
29/* good luck bulding a kmod_list outside of the library... makes this blacklist
30 * function rather pointless */
83b855a6 31#include <libkmod-internal.h>
bcca1b95
DM
32
33/* FIXME: hack, change name so we don't clash */
34#undef ERR
35#include "testsuite.h"
36
37static int blacklist_1(const struct test *t)
38{
39 struct kmod_ctx *ctx;
40 struct kmod_list *list = NULL, *l, *filtered;
41 struct kmod_module *mod;
42 int err;
43 size_t len = 0;
44
45 const char *names[] = { "pcspkr", "pcspkr2", "floppy", "ext4", NULL };
46 const char **name;
47
48 ctx = kmod_new(NULL, NULL);
49 if (ctx == NULL)
50 exit(EXIT_FAILURE);
51
52 for(name = names; *name; name++) {
53 err = kmod_module_new_from_name(ctx, *name, &mod);
54 if (err < 0)
55 goto fail_lookup;
56 list = kmod_list_append(list, mod);
57 }
58
59 err = kmod_module_apply_filter(ctx, KMOD_FILTER_BLACKLIST, list,
60 &filtered);
61 if (err < 0) {
62 ERR("Could not filter: %s\n", strerror(-err));
63 goto fail;
64 }
65 if (filtered == NULL) {
66 ERR("All modules were filtered out!\n");
67 goto fail;
68 }
69
70 kmod_list_foreach(l, filtered) {
71 const char *modname;
72 mod = kmod_module_get_module(l);
73 modname = kmod_module_get_name(mod);
74 if (strcmp("pcspkr", modname) == 0 || strcmp("floppy", modname) == 0)
75 goto fail;
76 len++;
77 kmod_module_unref(mod);
78 }
79
80 if (len != 2)
81 goto fail;
82
83 kmod_module_unref_list(filtered);
84 kmod_module_unref_list(list);
85 kmod_unref(ctx);
86
87 return EXIT_SUCCESS;
88
89fail:
90 kmod_module_unref_list(list);
91fail_lookup:
92 kmod_unref(ctx);
93 return EXIT_FAILURE;
94}
95static const struct test sblacklist_1 = {
96 .name = "blacklist_1",
97 .description = "check if modules are correctly blacklisted",
98 .func = blacklist_1,
99 .config = {
100 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-blacklist/",
101 },
102 .need_spawn = true,
103};
104
43289820 105TESTSUITE_MAIN();