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_initlib(const struct test *t)
35 const char *null_config = NULL;
37 ctx = kmod_new(NULL, &null_config);
45 DEFINE_TEST(test_initlib,
46 .description = "test if libkmod's init function work");
48 static noreturn int test_insert(const struct test *t)
51 struct kmod_module *mod;
52 const char *null_config = NULL;
55 ctx = kmod_new(NULL, &null_config);
59 err = kmod_module_new_from_path(ctx, "/mod-simple.ko", &mod);
61 ERR("could not create module from path: %m\n");
65 err = kmod_module_insert_module(mod, 0, NULL);
67 ERR("could not insert module: %m\n");
74 DEFINE_TEST(test_insert,
75 .description = "test if libkmod's insert_module returns ok",
77 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/",
78 [TC_INIT_MODULE_RETCODES] = "bla:1:20",
80 .modules_loaded = "mod_simple",
83 static noreturn int test_remove(const struct test *t)
86 struct kmod_module *mod_simple, *mod_bla;
87 const char *null_config = NULL;
90 ctx = kmod_new(NULL, &null_config);
94 err = kmod_module_new_from_name(ctx, "mod-simple", &mod_simple);
96 ERR("could not create module from name: %s\n", strerror(-err));
100 err = kmod_module_new_from_name(ctx, "bla", &mod_bla);
102 ERR("could not create module from name: %s\n", strerror(-err));
106 err = kmod_module_remove_module(mod_simple, 0);
108 ERR("could not remove module: %s\n", strerror(-err));
112 err = kmod_module_remove_module(mod_bla, 0);
113 if (err != -ENOENT) {
114 ERR("wrong return code for failure test: %d\n", err);
122 DEFINE_TEST(test_remove,
123 .description = "test if libkmod's remove_module returns ok",
125 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-remove/",
126 [TC_DELETE_MODULE_RETCODES] =
127 "mod-simple:0:0:bla:-1:" STRINGIFY(ENOENT),