]> git.ipfire.org Git - thirdparty/kmod.git/blob - testsuite/test-init.c
testsuite: macronify test definitions
[thirdparty/kmod.git] / testsuite / test-init.c
1 /*
2 * Copyright (C) 2012 ProFUSION embedded systems
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <stddef.h>
21 #include <string.h>
22 #include <errno.h>
23 #include <unistd.h>
24 #include <libkmod.h>
25
26 #include "testsuite.h"
27
28 static int test_initlib(const struct test *t)
29 {
30 struct kmod_ctx *ctx;
31 const char *null_config = NULL;
32
33 ctx = kmod_new(NULL, &null_config);
34 if (ctx == NULL)
35 exit(EXIT_FAILURE);
36
37 kmod_unref(ctx);
38
39 exit(EXIT_SUCCESS);
40 }
41 static DEFINE_TEST(test_initlib,
42 .description = "test if libkmod's init function work");
43
44 static int test_insert(const struct test *t)
45 {
46 struct kmod_ctx *ctx;
47 struct kmod_module *mod;
48 const char *null_config = NULL;
49 int err;
50
51 ctx = kmod_new(NULL, &null_config);
52 if (ctx == NULL)
53 exit(EXIT_FAILURE);
54
55 err = kmod_module_new_from_path(ctx, "/ext4-x86_64.ko", &mod);
56 if (err != 0) {
57 ERR("could not create module from path: %m\n");
58 exit(EXIT_FAILURE);
59 }
60
61 err = kmod_module_insert_module(mod, 0, NULL);
62 if (err != 0) {
63 ERR("could not insert module: %m\n");
64 exit(EXIT_FAILURE);
65 }
66 kmod_unref(ctx);
67
68 exit(EXIT_SUCCESS);
69 }
70 static DEFINE_TEST(test_insert,
71 .description = "test if libkmod's insert_module returns ok",
72 .config = {
73 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modinfo/",
74 [TC_INIT_MODULE_RETCODES] = "bla:1:20",
75 },
76 .need_spawn = true);
77
78 static int test_remove(const struct test *t)
79 {
80 struct kmod_ctx *ctx;
81 struct kmod_module *mod;
82 const char *null_config = NULL;
83 int err;
84
85 ctx = kmod_new(NULL, &null_config);
86 if (ctx == NULL)
87 exit(EXIT_FAILURE);
88
89 err = kmod_module_new_from_name(ctx, "ext4", &mod);
90 if (err != 0) {
91 ERR("could not create module from name: %m\n");
92 exit(EXIT_FAILURE);
93 }
94
95 err = kmod_module_remove_module(mod, 0);
96 if (err != 0) {
97 ERR("could not remove module: %m\n");
98 exit(EXIT_FAILURE);
99 }
100 kmod_unref(ctx);
101
102 exit(EXIT_SUCCESS);
103 }
104 static DEFINE_TEST(test_remove,
105 .description = "test if libkmod's remove_module returns ok",
106 .config = {
107 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modinfo/",
108 [TC_DELETE_MODULE_RETCODES] = "bla:1:20",
109 },
110 .need_spawn = true);
111
112 static const struct test *tests[] = {
113 &stest_initlib,
114 &stest_insert,
115 &stest_remove,
116 NULL,
117 };
118
119 TESTSUITE_MAIN(tests);