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",
57 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-init-load-resources/",
58 [TC_UNAME_R
] = "5.6.0",
63 static noreturn
int test_initlib(const struct test
*t
)
66 const char *null_config
= NULL
;
68 ctx
= kmod_new(NULL
, &null_config
);
76 DEFINE_TEST(test_initlib
,
77 .description
= "test if libkmod's init function work");
79 static noreturn
int test_insert(const struct test
*t
)
82 struct kmod_module
*mod
;
83 const char *null_config
= NULL
;
86 ctx
= kmod_new(NULL
, &null_config
);
90 err
= kmod_module_new_from_path(ctx
, "/mod-simple.ko", &mod
);
92 ERR("could not create module from path: %m\n");
96 err
= kmod_module_insert_module(mod
, 0, NULL
);
98 ERR("could not insert module: %m\n");
105 DEFINE_TEST(test_insert
,
106 .description
= "test if libkmod's insert_module returns ok",
108 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-init/",
109 [TC_INIT_MODULE_RETCODES
] = "bla:1:20",
111 .modules_loaded
= "mod_simple",
114 static noreturn
int test_remove(const struct test
*t
)
116 struct kmod_ctx
*ctx
;
117 struct kmod_module
*mod_simple
, *mod_bla
;
118 const char *null_config
= NULL
;
121 ctx
= kmod_new(NULL
, &null_config
);
125 err
= kmod_module_new_from_name(ctx
, "mod-simple", &mod_simple
);
127 ERR("could not create module from name: %s\n", strerror(-err
));
131 err
= kmod_module_new_from_name(ctx
, "bla", &mod_bla
);
133 ERR("could not create module from name: %s\n", strerror(-err
));
137 err
= kmod_module_remove_module(mod_simple
, 0);
139 ERR("could not remove module: %s\n", strerror(-err
));
143 err
= kmod_module_remove_module(mod_bla
, 0);
144 if (err
!= -ENOENT
) {
145 ERR("wrong return code for failure test: %d\n", err
);
153 DEFINE_TEST(test_remove
,
154 .description
= "test if libkmod's remove_module returns ok",
156 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-remove/",
157 [TC_DELETE_MODULE_RETCODES
] =
158 "mod-simple:0:0:bla:-1:" STRINGIFY(ENOENT
),