]> git.ipfire.org Git - thirdparty/kmod.git/blame - testsuite/test-dependencies.c
testsuite: depmod: check netsted loops reporting
[thirdparty/kmod.git] / testsuite / test-dependencies.c
CommitLineData
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 14 * You should have received a copy of the GNU Lesser General Public
dea2dfee 15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
c88aec70
DM
16 */
17
c88aec70 18#include <errno.h>
c88aec70 19#include <inttypes.h>
c2e4286b
LDM
20#include <stddef.h>
21#include <stdio.h>
22#include <stdlib.h>
c88aec70 23#include <string.h>
c2e4286b
LDM
24#include <unistd.h>
25
5c42c5fc
LDM
26#include <shared/util.h>
27
f357866d 28#include <libkmod/libkmod.h>
c88aec70
DM
29
30#include "testsuite.h"
c2e4286b 31
c88aec70
DM
32#define TEST_UNAME "4.0.20-kmod"
33
450c1f03 34static noreturn int test_dependencies(const struct test *t)
c88aec70
DM
35{
36 struct kmod_ctx *ctx;
d2db083a 37 struct kmod_module *mod = NULL;
c88aec70
DM
38 struct kmod_list *list, *l;
39 int err;
40 size_t len = 0;
450c1f03 41 int fooa = 0, foob = 0, fooc = 0;
c88aec70
DM
42
43 ctx = kmod_new(NULL, NULL);
44 if (ctx == NULL)
450c1f03 45 exit(EXIT_FAILURE);
c88aec70 46
450c1f03 47 err = kmod_module_new_from_name(ctx, "mod-foo", &mod);
d2db083a 48 if (err < 0 || mod == NULL) {
c88aec70 49 kmod_unref(ctx);
450c1f03 50 exit(EXIT_FAILURE);
c88aec70
DM
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
450c1f03
LDM
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;
c88aec70 65
450c1f03 66 fprintf(stderr, "name=%s", name);
c88aec70
DM
67 kmod_module_unref(m);
68 len++;
69 }
70
450c1f03
LDM
71 /* fooa, foob, fooc */
72 if (len != 3 || !fooa || !foob || !fooc)
73 exit(EXIT_FAILURE);
c88aec70
DM
74
75 kmod_module_unref_list(list);
76 kmod_module_unref(mod);
77 kmod_unref(ctx);
78
450c1f03 79 exit(EXIT_SUCCESS);
c88aec70 80}
d2db083a 81DEFINE_TEST(test_dependencies,
c88aec70 82 .description = "test if kmod_module_get_dependencies works",
c88aec70 83 .config = {
c88aec70 84 [TC_UNAME_R] = TEST_UNAME,
450c1f03
LDM
85 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/",
86 },
87 .need_spawn = true);
c88aec70 88
43289820 89TESTSUITE_MAIN();