Dan McGee | c88aec7 | 2012-02-22 23:56:59 -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 | c88aec7 | 2012-02-22 23:56:59 -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 | c88aec7 | 2012-02-22 23:56:59 -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 | c88aec7 | 2012-02-22 23:56:59 -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 | c88aec7 | 2012-02-22 23:56:59 -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 | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -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 | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 29 | |
| 30 | #include "testsuite.h" |
Lucas De Marchi | c2e4286 | 2014-10-03 01:41:42 -0300 | [diff] [blame] | 31 | |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 32 | #define TEST_UNAME "4.0.20-kmod" |
| 33 | |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 34 | static noreturn int test_dependencies(const struct test *t) |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 35 | { |
| 36 | struct kmod_ctx *ctx; |
Lucas De Marchi | d2db083 | 2015-02-02 23:55:56 -0200 | [diff] [blame] | 37 | struct kmod_module *mod = NULL; |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 38 | struct kmod_list *list, *l; |
| 39 | int err; |
| 40 | size_t len = 0; |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 41 | int fooa = 0, foob = 0, fooc = 0; |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 42 | |
| 43 | ctx = kmod_new(NULL, NULL); |
| 44 | if (ctx == NULL) |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 45 | exit(EXIT_FAILURE); |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 46 | |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 47 | err = kmod_module_new_from_name(ctx, "mod-foo", &mod); |
Lucas De Marchi | d2db083 | 2015-02-02 23:55:56 -0200 | [diff] [blame] | 48 | if (err < 0 || mod == NULL) { |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 49 | kmod_unref(ctx); |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 50 | exit(EXIT_FAILURE); |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | list = kmod_module_get_dependencies(mod); |
| 54 | |
| 55 | kmod_list_foreach(l, list) { |
| 56 | struct kmod_module *m = kmod_module_get_module(l); |
| 57 | const char *name = kmod_module_get_name(m); |
| 58 | |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 59 | if (streq(name, "mod_foo_a")) |
| 60 | fooa = 1; |
| 61 | if (streq(name, "mod_foo_b")) |
| 62 | foob = 1; |
| 63 | else if (streq(name, "mod_foo_c")) |
| 64 | fooc = 1; |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 65 | |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 66 | fprintf(stderr, "name=%s", name); |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 67 | kmod_module_unref(m); |
| 68 | len++; |
| 69 | } |
| 70 | |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 71 | /* fooa, foob, fooc */ |
| 72 | if (len != 3 || !fooa || !foob || !fooc) |
| 73 | exit(EXIT_FAILURE); |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 74 | |
| 75 | kmod_module_unref_list(list); |
| 76 | kmod_module_unref(mod); |
| 77 | kmod_unref(ctx); |
| 78 | |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 79 | exit(EXIT_SUCCESS); |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 80 | } |
Lucas De Marchi | d2db083 | 2015-02-02 23:55:56 -0200 | [diff] [blame] | 81 | DEFINE_TEST(test_dependencies, |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 82 | .description = "test if kmod_module_get_dependencies works", |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 83 | .config = { |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 84 | [TC_UNAME_R] = TEST_UNAME, |
Lucas De Marchi | 450c1f0 | 2015-02-03 00:24:33 -0200 | [diff] [blame] | 85 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/", |
| 86 | }, |
| 87 | .need_spawn = true); |
Dan McGee | c88aec7 | 2012-02-22 23:56:59 -0600 | [diff] [blame] | 88 | |
Lucas De Marchi | 4328982 | 2014-10-09 14:29:04 -0300 | [diff] [blame] | 89 | TESTSUITE_MAIN(); |