blob: 38f5fc1c725bf28d8db043d70f31bd811d1569fa [file] [log] [blame]
Dan McGeec88aec72012-02-22 23:56:59 -06001/*
Lucas De Marchie6b0e492013-01-16 11:27:21 -02002 * Copyright (C) 2011-2013 ProFUSION embedded systems
Dan McGeec88aec72012-02-22 23:56:59 -06003 *
Lucas De Marchie1b1ab22012-07-10 09:42:24 -03004 * 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 McGeec88aec72012-02-22 23:56:59 -06008 *
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 Marchie1b1ab22012-07-10 09:42:24 -030011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
Dan McGeec88aec72012-02-22 23:56:59 -060013 *
Lucas De Marchie1b1ab22012-07-10 09:42:24 -030014 * You should have received a copy of the GNU Lesser General Public
Lucas De Marchidea2dfe2014-12-25 23:32:03 -020015 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Dan McGeec88aec72012-02-22 23:56:59 -060016 */
17
Lucas De Marchic2e42862014-10-03 01:41:42 -030018#include <errno.h>
19#include <inttypes.h>
20#include <stddef.h>
Dan McGeec88aec72012-02-22 23:56:59 -060021#include <stdio.h>
22#include <stdlib.h>
Dan McGeec88aec72012-02-22 23:56:59 -060023#include <string.h>
Lucas De Marchic2e42862014-10-03 01:41:42 -030024#include <unistd.h>
25
Lucas De Marchi5c42c5f2015-01-14 14:22:09 -020026#include <shared/util.h>
27
Lucas De Marchif3578662015-01-02 12:38:27 -020028#include <libkmod/libkmod.h>
Dan McGeec88aec72012-02-22 23:56:59 -060029
30#include "testsuite.h"
Lucas De Marchic2e42862014-10-03 01:41:42 -030031
Dan McGeec88aec72012-02-22 23:56:59 -060032#define TEST_UNAME "4.0.20-kmod"
33
Lucas De Marchi450c1f02015-02-03 00:24:33 -020034static noreturn int test_dependencies(const struct test *t)
Dan McGeec88aec72012-02-22 23:56:59 -060035{
36 struct kmod_ctx *ctx;
Lucas De Marchid2db0832015-02-02 23:55:56 -020037 struct kmod_module *mod = NULL;
Dan McGeec88aec72012-02-22 23:56:59 -060038 struct kmod_list *list, *l;
39 int err;
40 size_t len = 0;
Lucas De Marchi450c1f02015-02-03 00:24:33 -020041 int fooa = 0, foob = 0, fooc = 0;
Dan McGeec88aec72012-02-22 23:56:59 -060042
43 ctx = kmod_new(NULL, NULL);
44 if (ctx == NULL)
Lucas De Marchi450c1f02015-02-03 00:24:33 -020045 exit(EXIT_FAILURE);
Dan McGeec88aec72012-02-22 23:56:59 -060046
Lucas De Marchi450c1f02015-02-03 00:24:33 -020047 err = kmod_module_new_from_name(ctx, "mod-foo", &mod);
Lucas De Marchid2db0832015-02-02 23:55:56 -020048 if (err < 0 || mod == NULL) {
Dan McGeec88aec72012-02-22 23:56:59 -060049 kmod_unref(ctx);
Lucas De Marchi450c1f02015-02-03 00:24:33 -020050 exit(EXIT_FAILURE);
Dan McGeec88aec72012-02-22 23:56:59 -060051 }
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 Marchi450c1f02015-02-03 00:24:33 -020059 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 McGeec88aec72012-02-22 23:56:59 -060065
Lucas De Marchi450c1f02015-02-03 00:24:33 -020066 fprintf(stderr, "name=%s", name);
Dan McGeec88aec72012-02-22 23:56:59 -060067 kmod_module_unref(m);
68 len++;
69 }
70
Lucas De Marchi450c1f02015-02-03 00:24:33 -020071 /* fooa, foob, fooc */
72 if (len != 3 || !fooa || !foob || !fooc)
73 exit(EXIT_FAILURE);
Dan McGeec88aec72012-02-22 23:56:59 -060074
75 kmod_module_unref_list(list);
76 kmod_module_unref(mod);
77 kmod_unref(ctx);
78
Lucas De Marchi450c1f02015-02-03 00:24:33 -020079 exit(EXIT_SUCCESS);
Dan McGeec88aec72012-02-22 23:56:59 -060080}
Lucas De Marchid2db0832015-02-02 23:55:56 -020081DEFINE_TEST(test_dependencies,
Dan McGeec88aec72012-02-22 23:56:59 -060082 .description = "test if kmod_module_get_dependencies works",
Dan McGeec88aec72012-02-22 23:56:59 -060083 .config = {
Dan McGeec88aec72012-02-22 23:56:59 -060084 [TC_UNAME_R] = TEST_UNAME,
Lucas De Marchi450c1f02015-02-03 00:24:33 -020085 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/",
86 },
87 .need_spawn = true);
Dan McGeec88aec72012-02-22 23:56:59 -060088
Lucas De Marchi43289822014-10-09 14:29:04 -030089TESTSUITE_MAIN();