]>
Commit | Line | Data |
---|---|---|
c88aec70 | 1 | /* |
e6b0e49b | 2 | * Copyright (C) 2011-2013 ProFUSION embedded systems |
c88aec70 | 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. | |
c88aec70 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. | |
c88aec70 | 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 | |
c88aec70 DM |
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 | #include "testsuite.h" | |
29 | #define TEST_UNAME "4.0.20-kmod" | |
30 | ||
31 | static int test_dependencies(const struct test *t) | |
32 | { | |
33 | struct kmod_ctx *ctx; | |
34 | struct kmod_module *mod; | |
35 | struct kmod_list *list, *l; | |
36 | int err; | |
37 | size_t len = 0; | |
38 | int crc16 = 0, mbcache = 0, jbd2 = 0; | |
39 | ||
40 | ctx = kmod_new(NULL, NULL); | |
41 | if (ctx == NULL) | |
42 | return EXIT_FAILURE; | |
43 | ||
44 | err = kmod_module_new_from_name(ctx, "ext4", &mod); | |
45 | if (err < 0) { | |
46 | kmod_unref(ctx); | |
47 | return EXIT_FAILURE; | |
48 | } | |
49 | ||
50 | list = kmod_module_get_dependencies(mod); | |
51 | ||
52 | kmod_list_foreach(l, list) { | |
53 | struct kmod_module *m = kmod_module_get_module(l); | |
54 | const char *name = kmod_module_get_name(m); | |
55 | ||
56 | if (strcmp(name, "crc16") == 0) | |
57 | crc16 = 1; | |
58 | if (strcmp(name, "mbcache") == 0) | |
59 | mbcache = 1; | |
60 | else if (strcmp(name, "jbd2") == 0) | |
61 | jbd2 = 1; | |
62 | ||
63 | kmod_module_unref(m); | |
64 | len++; | |
65 | } | |
66 | ||
67 | /* crc16, mbcache, jbd2 */ | |
68 | if (len != 3 || !crc16 || !mbcache || !jbd2) | |
69 | return EXIT_FAILURE; | |
70 | ||
71 | kmod_module_unref_list(list); | |
72 | kmod_module_unref(mod); | |
73 | kmod_unref(ctx); | |
74 | ||
75 | return EXIT_SUCCESS; | |
76 | } | |
77 | static const struct test stest_dependencies = { | |
78 | .name = "test_dependencies", | |
79 | .description = "test if kmod_module_get_dependencies works", | |
80 | .func = test_dependencies, | |
81 | .config = { | |
82 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/", | |
83 | [TC_UNAME_R] = TEST_UNAME, | |
84 | }, | |
85 | .need_spawn = true, | |
86 | }; | |
87 | ||
88 | static const struct test *tests[] = { | |
89 | &stest_dependencies, | |
90 | NULL, | |
91 | }; | |
92 | ||
93 | TESTSUITE_MAIN(tests); |