2012-01-27 02:01:41 +07:00
|
|
|
/*
|
2013-01-16 20:27:21 +07:00
|
|
|
* Copyright (C) 2012-2013 ProFUSION embedded systems
|
2012-01-27 02:01:41 +07:00
|
|
|
*
|
2012-07-10 19:42:24 +07:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-01-27 02:01:41 +07:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-07-10 19:42:24 +07:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2012-01-27 02:01:41 +07:00
|
|
|
*
|
2012-07-10 19:42:24 +07:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2012-01-27 02:01:41 +07:00
|
|
|
*/
|
|
|
|
|
2012-01-25 06:53:27 +07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libkmod.h>
|
|
|
|
|
|
|
|
#include "testsuite.h"
|
|
|
|
|
2013-12-18 04:10:16 +07:00
|
|
|
static noreturn int test_initlib(const struct test *t)
|
2012-01-25 06:53:27 +07:00
|
|
|
{
|
|
|
|
struct kmod_ctx *ctx;
|
|
|
|
const char *null_config = NULL;
|
|
|
|
|
|
|
|
ctx = kmod_new(NULL, &null_config);
|
|
|
|
if (ctx == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
kmod_unref(ctx);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2012-02-07 19:46:46 +07:00
|
|
|
static DEFINE_TEST(test_initlib,
|
|
|
|
.description = "test if libkmod's init function work");
|
2012-01-26 11:09:28 +07:00
|
|
|
|
2013-12-18 04:10:16 +07:00
|
|
|
static noreturn int test_insert(const struct test *t)
|
2012-01-26 11:09:28 +07:00
|
|
|
{
|
|
|
|
struct kmod_ctx *ctx;
|
|
|
|
struct kmod_module *mod;
|
|
|
|
const char *null_config = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
ctx = kmod_new(NULL, &null_config);
|
|
|
|
if (ctx == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
err = kmod_module_new_from_path(ctx, "/ext4-x86_64.ko", &mod);
|
|
|
|
if (err != 0) {
|
|
|
|
ERR("could not create module from path: %m\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = kmod_module_insert_module(mod, 0, NULL);
|
|
|
|
if (err != 0) {
|
|
|
|
ERR("could not insert module: %m\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
kmod_unref(ctx);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2012-02-07 19:46:46 +07:00
|
|
|
static DEFINE_TEST(test_insert,
|
2012-01-26 11:09:28 +07:00
|
|
|
.description = "test if libkmod's insert_module returns ok",
|
|
|
|
.config = {
|
2012-05-25 10:24:58 +07:00
|
|
|
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/",
|
2012-01-26 11:09:28 +07:00
|
|
|
[TC_INIT_MODULE_RETCODES] = "bla:1:20",
|
|
|
|
},
|
2014-02-28 19:05:28 +07:00
|
|
|
.modules_loaded = "ext4",
|
2012-02-07 19:46:46 +07:00
|
|
|
.need_spawn = true);
|
2012-01-25 06:53:27 +07:00
|
|
|
|
2013-12-18 04:10:16 +07:00
|
|
|
static noreturn int test_remove(const struct test *t)
|
2012-01-27 01:10:41 +07:00
|
|
|
{
|
|
|
|
struct kmod_ctx *ctx;
|
|
|
|
struct kmod_module *mod;
|
|
|
|
const char *null_config = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
ctx = kmod_new(NULL, &null_config);
|
|
|
|
if (ctx == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
err = kmod_module_new_from_name(ctx, "ext4", &mod);
|
|
|
|
if (err != 0) {
|
|
|
|
ERR("could not create module from name: %m\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = kmod_module_remove_module(mod, 0);
|
|
|
|
if (err != 0) {
|
|
|
|
ERR("could not remove module: %m\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
kmod_unref(ctx);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2012-02-07 19:46:46 +07:00
|
|
|
static DEFINE_TEST(test_remove,
|
2012-01-27 01:10:41 +07:00
|
|
|
.description = "test if libkmod's remove_module returns ok",
|
|
|
|
.config = {
|
2012-05-25 10:24:58 +07:00
|
|
|
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-remove/",
|
2012-01-27 01:10:41 +07:00
|
|
|
[TC_DELETE_MODULE_RETCODES] = "bla:1:20",
|
|
|
|
},
|
2012-02-07 19:46:46 +07:00
|
|
|
.need_spawn = true);
|
2012-01-27 01:10:41 +07:00
|
|
|
|
2012-01-25 06:53:27 +07:00
|
|
|
static const struct test *tests[] = {
|
2012-01-26 11:09:28 +07:00
|
|
|
&stest_initlib,
|
|
|
|
&stest_insert,
|
2012-01-27 01:10:41 +07:00
|
|
|
&stest_remove,
|
2012-01-25 06:53:27 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2012-02-07 19:09:20 +07:00
|
|
|
TESTSUITE_MAIN(tests);
|