]> git.ipfire.org Git - thirdparty/kmod.git/blob - testsuite/test-dependencies.c
ac7a08fd30c570fbf0428a639787a3b31ff2cb0c
[thirdparty/kmod.git] / testsuite / test-dependencies.c
1 /*
2 * Copyright (C) 2011-2013 ProFUSION embedded systems
3 *
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.
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <errno.h>
19 #include <inttypes.h>
20 #include <stddef.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include <libkmod/libkmod.h>
27
28 #include "testsuite.h"
29
30 #define TEST_UNAME "4.0.20-kmod"
31
32 static int test_dependencies(const struct test *t)
33 {
34 struct kmod_ctx *ctx;
35 struct kmod_module *mod;
36 struct kmod_list *list, *l;
37 int err;
38 size_t len = 0;
39 int crc16 = 0, mbcache = 0, jbd2 = 0;
40
41 ctx = kmod_new(NULL, NULL);
42 if (ctx == NULL)
43 return EXIT_FAILURE;
44
45 err = kmod_module_new_from_name(ctx, "ext4", &mod);
46 if (err < 0) {
47 kmod_unref(ctx);
48 return EXIT_FAILURE;
49 }
50
51 list = kmod_module_get_dependencies(mod);
52
53 kmod_list_foreach(l, list) {
54 struct kmod_module *m = kmod_module_get_module(l);
55 const char *name = kmod_module_get_name(m);
56
57 if (strcmp(name, "crc16") == 0)
58 crc16 = 1;
59 if (strcmp(name, "mbcache") == 0)
60 mbcache = 1;
61 else if (strcmp(name, "jbd2") == 0)
62 jbd2 = 1;
63
64 kmod_module_unref(m);
65 len++;
66 }
67
68 /* crc16, mbcache, jbd2 */
69 if (len != 3 || !crc16 || !mbcache || !jbd2)
70 return EXIT_FAILURE;
71
72 kmod_module_unref_list(list);
73 kmod_module_unref(mod);
74 kmod_unref(ctx);
75
76 return EXIT_SUCCESS;
77 }
78 static const struct test stest_dependencies = {
79 .name = "test_dependencies",
80 .description = "test if kmod_module_get_dependencies works",
81 .func = test_dependencies,
82 .config = {
83 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/",
84 [TC_UNAME_R] = TEST_UNAME,
85 },
86 .need_spawn = true,
87 };
88
89 TESTSUITE_MAIN();