]> git.ipfire.org Git - thirdparty/kmod.git/blame - testsuite/test-init.c
Remove FSF mailing address
[thirdparty/kmod.git] / testsuite / test-init.c
CommitLineData
e701e381 1/*
e6b0e49b 2 * Copyright (C) 2012-2013 ProFUSION embedded systems
e701e381 3 *
e1b1ab24
LDM
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.
e701e381
LDM
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e1b1ab24
LDM
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
e701e381 13 *
e1b1ab24 14 * You should have received a copy of the GNU Lesser General Public
dea2dfee 15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
e701e381
LDM
16 */
17
c2e4286b
LDM
18#include <errno.h>
19#include <inttypes.h>
20#include <stddef.h>
eebca81e
LDM
21#include <stdio.h>
22#include <stdlib.h>
eebca81e 23#include <string.h>
eebca81e 24#include <unistd.h>
c2e4286b 25
eebca81e
LDM
26#include <libkmod.h>
27
28#include "testsuite.h"
29
d96ca9c4 30static noreturn int test_initlib(const struct test *t)
eebca81e
LDM
31{
32 struct kmod_ctx *ctx;
33 const char *null_config = NULL;
34
35 ctx = kmod_new(NULL, &null_config);
36 if (ctx == NULL)
37 exit(EXIT_FAILURE);
38
39 kmod_unref(ctx);
40
41 exit(EXIT_SUCCESS);
42}
f1155c15 43DEFINE_TEST(test_initlib,
c5d81989 44 .description = "test if libkmod's init function work");
53646fc5 45
d96ca9c4 46static noreturn int test_insert(const struct test *t)
53646fc5
LDM
47{
48 struct kmod_ctx *ctx;
49 struct kmod_module *mod;
50 const char *null_config = NULL;
51 int err;
52
53 ctx = kmod_new(NULL, &null_config);
54 if (ctx == NULL)
55 exit(EXIT_FAILURE);
56
57 err = kmod_module_new_from_path(ctx, "/ext4-x86_64.ko", &mod);
58 if (err != 0) {
59 ERR("could not create module from path: %m\n");
60 exit(EXIT_FAILURE);
61 }
62
63 err = kmod_module_insert_module(mod, 0, NULL);
64 if (err != 0) {
65 ERR("could not insert module: %m\n");
66 exit(EXIT_FAILURE);
67 }
68 kmod_unref(ctx);
69
70 exit(EXIT_SUCCESS);
71}
f1155c15 72DEFINE_TEST(test_insert,
53646fc5 73 .description = "test if libkmod's insert_module returns ok",
53646fc5 74 .config = {
ada97199 75 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/",
53646fc5
LDM
76 [TC_INIT_MODULE_RETCODES] = "bla:1:20",
77 },
88ac4084 78 .modules_loaded = "ext4",
c5d81989 79 .need_spawn = true);
eebca81e 80
d96ca9c4 81static noreturn int test_remove(const struct test *t)
f6ef5d6b
LDM
82{
83 struct kmod_ctx *ctx;
84 struct kmod_module *mod;
85 const char *null_config = NULL;
86 int err;
87
88 ctx = kmod_new(NULL, &null_config);
89 if (ctx == NULL)
90 exit(EXIT_FAILURE);
91
92 err = kmod_module_new_from_name(ctx, "ext4", &mod);
93 if (err != 0) {
94 ERR("could not create module from name: %m\n");
95 exit(EXIT_FAILURE);
96 }
97
98 err = kmod_module_remove_module(mod, 0);
99 if (err != 0) {
100 ERR("could not remove module: %m\n");
101 exit(EXIT_FAILURE);
102 }
103 kmod_unref(ctx);
104
105 exit(EXIT_SUCCESS);
106}
f1155c15 107DEFINE_TEST(test_remove,
f6ef5d6b 108 .description = "test if libkmod's remove_module returns ok",
f6ef5d6b 109 .config = {
ada97199 110 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-remove/",
f6ef5d6b
LDM
111 [TC_DELETE_MODULE_RETCODES] = "bla:1:20",
112 },
c5d81989 113 .need_spawn = true);
f6ef5d6b 114
43289820 115TESTSUITE_MAIN();