]> git.ipfire.org Git - thirdparty/kmod.git/blob - testsuite/test-dependencies.c
testsuite: remove now unused array of tests
[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, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <errno.h>
20 #include <inttypes.h>
21 #include <stddef.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26
27 #include <libkmod.h>
28
29 #include "testsuite.h"
30
31 #define TEST_UNAME "4.0.20-kmod"
32
33 static int test_dependencies(const struct test *t)
34 {
35 struct kmod_ctx *ctx;
36 struct kmod_module *mod;
37 struct kmod_list *list, *l;
38 int err;
39 size_t len = 0;
40 int crc16 = 0, mbcache = 0, jbd2 = 0;
41
42 ctx = kmod_new(NULL, NULL);
43 if (ctx == NULL)
44 return EXIT_FAILURE;
45
46 err = kmod_module_new_from_name(ctx, "ext4", &mod);
47 if (err < 0) {
48 kmod_unref(ctx);
49 return EXIT_FAILURE;
50 }
51
52 list = kmod_module_get_dependencies(mod);
53
54 kmod_list_foreach(l, list) {
55 struct kmod_module *m = kmod_module_get_module(l);
56 const char *name = kmod_module_get_name(m);
57
58 if (strcmp(name, "crc16") == 0)
59 crc16 = 1;
60 if (strcmp(name, "mbcache") == 0)
61 mbcache = 1;
62 else if (strcmp(name, "jbd2") == 0)
63 jbd2 = 1;
64
65 kmod_module_unref(m);
66 len++;
67 }
68
69 /* crc16, mbcache, jbd2 */
70 if (len != 3 || !crc16 || !mbcache || !jbd2)
71 return EXIT_FAILURE;
72
73 kmod_module_unref_list(list);
74 kmod_module_unref(mod);
75 kmod_unref(ctx);
76
77 return EXIT_SUCCESS;
78 }
79 static const struct test stest_dependencies = {
80 .name = "test_dependencies",
81 .description = "test if kmod_module_get_dependencies works",
82 .func = test_dependencies,
83 .config = {
84 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/",
85 [TC_UNAME_R] = TEST_UNAME,
86 },
87 .need_spawn = true,
88 };
89
90 TESTSUITE_MAIN();