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 |
Lucas De Marchi | dea2dfe | 2014-12-25 23:32:03 -0200 | [diff] [blame] | 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 16 | */ |
| 17 | |
Lucas De Marchi | c2e4286 | 2014-10-03 01:41:42 -0300 | [diff] [blame] | 18 | #include <errno.h> |
| 19 | #include <inttypes.h> |
| 20 | #include <stddef.h> |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 23 | #include <string.h> |
Lucas De Marchi | c2e4286 | 2014-10-03 01:41:42 -0300 | [diff] [blame] | 24 | #include <unistd.h> |
| 25 | |
Lucas De Marchi | 5c42c5f | 2015-01-14 14:22:09 -0200 | [diff] [blame] | 26 | #include <shared/util.h> |
| 27 | |
Lucas De Marchi | f357866 | 2015-01-02 12:38:27 -0200 | [diff] [blame] | 28 | #include <libkmod/libkmod.h> |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 29 | |
| 30 | /* good luck bulding a kmod_list outside of the library... makes this blacklist |
| 31 | * function rather pointless */ |
Lucas De Marchi | 1315123 | 2014-12-25 23:07:48 -0200 | [diff] [blame] | 32 | #include <libkmod/libkmod-internal.h> |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 33 | |
| 34 | /* FIXME: hack, change name so we don't clash */ |
| 35 | #undef ERR |
| 36 | #include "testsuite.h" |
| 37 | |
| 38 | static int blacklist_1(const struct test *t) |
| 39 | { |
| 40 | struct kmod_ctx *ctx; |
| 41 | struct kmod_list *list = NULL, *l, *filtered; |
| 42 | struct kmod_module *mod; |
| 43 | int err; |
| 44 | size_t len = 0; |
| 45 | |
| 46 | const char *names[] = { "pcspkr", "pcspkr2", "floppy", "ext4", NULL }; |
| 47 | const char **name; |
| 48 | |
| 49 | ctx = kmod_new(NULL, NULL); |
| 50 | if (ctx == NULL) |
| 51 | exit(EXIT_FAILURE); |
| 52 | |
| 53 | for(name = names; *name; name++) { |
| 54 | err = kmod_module_new_from_name(ctx, *name, &mod); |
| 55 | if (err < 0) |
| 56 | goto fail_lookup; |
| 57 | list = kmod_list_append(list, mod); |
| 58 | } |
| 59 | |
| 60 | err = kmod_module_apply_filter(ctx, KMOD_FILTER_BLACKLIST, list, |
| 61 | &filtered); |
| 62 | if (err < 0) { |
| 63 | ERR("Could not filter: %s\n", strerror(-err)); |
| 64 | goto fail; |
| 65 | } |
| 66 | if (filtered == NULL) { |
| 67 | ERR("All modules were filtered out!\n"); |
| 68 | goto fail; |
| 69 | } |
| 70 | |
| 71 | kmod_list_foreach(l, filtered) { |
| 72 | const char *modname; |
| 73 | mod = kmod_module_get_module(l); |
| 74 | modname = kmod_module_get_name(mod); |
Lucas De Marchi | 5c42c5f | 2015-01-14 14:22:09 -0200 | [diff] [blame] | 75 | if (streq("pcspkr", modname) || streq("floppy", modname)) |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 76 | goto fail; |
| 77 | len++; |
| 78 | kmod_module_unref(mod); |
| 79 | } |
| 80 | |
| 81 | if (len != 2) |
| 82 | goto fail; |
| 83 | |
| 84 | kmod_module_unref_list(filtered); |
| 85 | kmod_module_unref_list(list); |
| 86 | kmod_unref(ctx); |
| 87 | |
| 88 | return EXIT_SUCCESS; |
| 89 | |
| 90 | fail: |
| 91 | kmod_module_unref_list(list); |
| 92 | fail_lookup: |
| 93 | kmod_unref(ctx); |
| 94 | return EXIT_FAILURE; |
| 95 | } |
Marcus Meissner | 0af8f78 | 2015-02-22 11:48:13 +0100 | [diff] [blame] | 96 | |
| 97 | DEFINE_TEST(blacklist_1, |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 98 | .description = "check if modules are correctly blacklisted", |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 99 | .config = { |
| 100 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-blacklist/", |
| 101 | }, |
| 102 | .need_spawn = true, |
Marcus Meissner | 0af8f78 | 2015-02-22 11:48:13 +0100 | [diff] [blame] | 103 | ); |
Dan McGee | bcca1b9 | 2012-02-22 23:56:58 -0600 | [diff] [blame] | 104 | |
Lucas De Marchi | 4328982 | 2014-10-09 14:29:04 -0300 | [diff] [blame] | 105 | TESTSUITE_MAIN(); |