Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 1 | /* |
Lucas De Marchi | e6b0e49 | 2013-01-16 11:27:21 -0200 | [diff] [blame^] | 2 | * Copyright (C) 2011-2013 ProFUSION embedded systems |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 3 | * |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 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. |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 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 |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 13 | * |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 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 |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <stddef.h> |
| 22 | #include <errno.h> |
| 23 | #include <unistd.h> |
| 24 | #include <inttypes.h> |
| 25 | #include <string.h> |
| 26 | #include <libkmod.h> |
| 27 | |
| 28 | /* good luck bulding a kmod_list outside of the library... makes this blacklist |
| 29 | * function rather pointless */ |
| 30 | #include <libkmod-private.h> |
| 31 | |
| 32 | /* FIXME: hack, change name so we don't clash */ |
| 33 | #undef ERR |
| 34 | #include "testsuite.h" |
| 35 | |
| 36 | static int blacklist_1(const struct test *t) |
| 37 | { |
| 38 | struct kmod_ctx *ctx; |
| 39 | struct kmod_list *list = NULL, *l, *filtered; |
| 40 | struct kmod_module *mod; |
| 41 | int err; |
| 42 | size_t len = 0; |
| 43 | |
| 44 | const char *names[] = { "pcspkr", "pcspkr2", "floppy", "ext4", NULL }; |
| 45 | const char **name; |
| 46 | |
| 47 | ctx = kmod_new(NULL, NULL); |
| 48 | if (ctx == NULL) |
| 49 | exit(EXIT_FAILURE); |
| 50 | |
| 51 | for(name = names; *name; name++) { |
| 52 | err = kmod_module_new_from_name(ctx, *name, &mod); |
| 53 | if (err < 0) |
| 54 | goto fail_lookup; |
| 55 | list = kmod_list_append(list, mod); |
| 56 | } |
| 57 | |
| 58 | err = kmod_module_apply_filter(ctx, KMOD_FILTER_BLACKLIST, list, |
| 59 | &filtered); |
| 60 | if (err < 0) { |
| 61 | ERR("Could not filter: %s\n", strerror(-err)); |
| 62 | goto fail; |
| 63 | } |
| 64 | if (filtered == NULL) { |
| 65 | ERR("All modules were filtered out!\n"); |
| 66 | goto fail; |
| 67 | } |
| 68 | |
| 69 | kmod_list_foreach(l, filtered) { |
| 70 | const char *modname; |
| 71 | mod = kmod_module_get_module(l); |
| 72 | modname = kmod_module_get_name(mod); |
| 73 | if (strcmp("pcspkr", modname) == 0 || strcmp("floppy", modname) == 0) |
| 74 | goto fail; |
| 75 | len++; |
| 76 | kmod_module_unref(mod); |
| 77 | } |
| 78 | |
| 79 | if (len != 2) |
| 80 | goto fail; |
| 81 | |
| 82 | kmod_module_unref_list(filtered); |
| 83 | kmod_module_unref_list(list); |
| 84 | kmod_unref(ctx); |
| 85 | |
| 86 | return EXIT_SUCCESS; |
| 87 | |
| 88 | fail: |
| 89 | kmod_module_unref_list(list); |
| 90 | fail_lookup: |
| 91 | kmod_unref(ctx); |
| 92 | return EXIT_FAILURE; |
| 93 | } |
| 94 | static const struct test sblacklist_1 = { |
| 95 | .name = "blacklist_1", |
| 96 | .description = "check if modules are correctly blacklisted", |
| 97 | .func = blacklist_1, |
| 98 | .config = { |
| 99 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-blacklist/", |
| 100 | }, |
| 101 | .need_spawn = true, |
| 102 | }; |
| 103 | |
| 104 | static const struct test *tests[] = { |
| 105 | &sblacklist_1, |
| 106 | NULL, |
| 107 | }; |
| 108 | |
| 109 | TESTSUITE_MAIN(tests); |