2 * Copyright (C) 2012-2013 ProFUSION embedded systems
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.
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.
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/>.
26 #include <shared/macro.h>
28 #include <libkmod/libkmod.h>
30 #include "testsuite.h"
32 static noreturn
int test_load_resources(const struct test
*t
)
35 const char *null_config
= NULL
;
38 ctx
= kmod_new(NULL
, &null_config
);
42 kmod_set_log_priority(ctx
, 7);
44 err
= kmod_load_resources(ctx
);
46 ERR("could not load libkmod resources: %s\n", strerror(-err
));
54 DEFINE_TEST(test_load_resources
,
55 .description
= "test if kmod_load_resources works (recent modprobe on kernel without modules.builtin.modinfo)",
57 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-init-load-resources/",
58 [TC_UNAME_R
] = "5.6.0",
62 DEFINE_TEST(test_load_resources
,
63 .description
= "test if kmod_load_resources works with empty modules.builtin.aliases.bin (recent depmod on kernel without modules.builtin.modinfo)",
65 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-init-load-resources-empty-builtin-aliases-bin/",
66 [TC_UNAME_R
] = "5.6.0",
70 static noreturn
int test_initlib(const struct test
*t
)
73 const char *null_config
= NULL
;
75 ctx
= kmod_new(NULL
, &null_config
);
83 DEFINE_TEST(test_initlib
,
84 .description
= "test if libkmod's init function work");
86 static noreturn
int test_insert(const struct test
*t
)
89 struct kmod_module
*mod
;
90 const char *null_config
= NULL
;
93 ctx
= kmod_new(NULL
, &null_config
);
97 err
= kmod_module_new_from_path(ctx
, "/mod-simple.ko", &mod
);
99 ERR("could not create module from path: %m\n");
103 err
= kmod_module_insert_module(mod
, 0, NULL
);
105 ERR("could not insert module: %m\n");
112 DEFINE_TEST(test_insert
,
113 .description
= "test if libkmod's insert_module returns ok",
115 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-init/",
116 [TC_INIT_MODULE_RETCODES
] = "bla:1:20",
118 .modules_loaded
= "mod_simple",
121 static noreturn
int test_remove(const struct test
*t
)
123 struct kmod_ctx
*ctx
;
124 struct kmod_module
*mod_simple
, *mod_bla
;
125 const char *null_config
= NULL
;
128 ctx
= kmod_new(NULL
, &null_config
);
132 err
= kmod_module_new_from_name(ctx
, "mod-simple", &mod_simple
);
134 ERR("could not create module from name: %s\n", strerror(-err
));
138 err
= kmod_module_new_from_name(ctx
, "bla", &mod_bla
);
140 ERR("could not create module from name: %s\n", strerror(-err
));
144 err
= kmod_module_remove_module(mod_simple
, 0);
146 ERR("could not remove module: %s\n", strerror(-err
));
150 err
= kmod_module_remove_module(mod_bla
, 0);
151 if (err
!= -ENOENT
) {
152 ERR("wrong return code for failure test: %d\n", err
);
160 DEFINE_TEST(test_remove
,
161 .description
= "test if libkmod's remove_module returns ok",
163 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-remove/",
164 [TC_DELETE_MODULE_RETCODES
] =
165 "mod-simple:0:0:bla:-1:" STRINGIFY(ENOENT
),