]> git.ipfire.org Git - thirdparty/kmod.git/blob - testsuite/test-init.c
Move static keyword to DEFINE_TEST macro
[thirdparty/kmod.git] / testsuite / test-init.c
1 /*
2 * Copyright (C) 2012-2013 ProFUSION embedded systems
3 *
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.
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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <errno.h>
20 #include <inttypes.h>
21 #include <stddef.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26
27 #include <libkmod.h>
28
29 #include "testsuite.h"
30
31 static noreturn int test_initlib(const struct test *t)
32 {
33 struct kmod_ctx *ctx;
34 const char *null_config = NULL;
35
36 ctx = kmod_new(NULL, &null_config);
37 if (ctx == NULL)
38 exit(EXIT_FAILURE);
39
40 kmod_unref(ctx);
41
42 exit(EXIT_SUCCESS);
43 }
44 DEFINE_TEST(test_initlib,
45 .description = "test if libkmod's init function work");
46
47 static noreturn int test_insert(const struct test *t)
48 {
49 struct kmod_ctx *ctx;
50 struct kmod_module *mod;
51 const char *null_config = NULL;
52 int err;
53
54 ctx = kmod_new(NULL, &null_config);
55 if (ctx == NULL)
56 exit(EXIT_FAILURE);
57
58 err = kmod_module_new_from_path(ctx, "/ext4-x86_64.ko", &mod);
59 if (err != 0) {
60 ERR("could not create module from path: %m\n");
61 exit(EXIT_FAILURE);
62 }
63
64 err = kmod_module_insert_module(mod, 0, NULL);
65 if (err != 0) {
66 ERR("could not insert module: %m\n");
67 exit(EXIT_FAILURE);
68 }
69 kmod_unref(ctx);
70
71 exit(EXIT_SUCCESS);
72 }
73 DEFINE_TEST(test_insert,
74 .description = "test if libkmod's insert_module returns ok",
75 .config = {
76 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/",
77 [TC_INIT_MODULE_RETCODES] = "bla:1:20",
78 },
79 .modules_loaded = "ext4",
80 .need_spawn = true);
81
82 static noreturn int test_remove(const struct test *t)
83 {
84 struct kmod_ctx *ctx;
85 struct kmod_module *mod;
86 const char *null_config = NULL;
87 int err;
88
89 ctx = kmod_new(NULL, &null_config);
90 if (ctx == NULL)
91 exit(EXIT_FAILURE);
92
93 err = kmod_module_new_from_name(ctx, "ext4", &mod);
94 if (err != 0) {
95 ERR("could not create module from name: %m\n");
96 exit(EXIT_FAILURE);
97 }
98
99 err = kmod_module_remove_module(mod, 0);
100 if (err != 0) {
101 ERR("could not remove module: %m\n");
102 exit(EXIT_FAILURE);
103 }
104 kmod_unref(ctx);
105
106 exit(EXIT_SUCCESS);
107 }
108 DEFINE_TEST(test_remove,
109 .description = "test if libkmod's remove_module returns ok",
110 .config = {
111 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-remove/",
112 [TC_DELETE_MODULE_RETCODES] = "bla:1:20",
113 },
114 .need_spawn = true);
115
116 static const struct test *tests[] = {
117 &stest_initlib,
118 &stest_insert,
119 &stest_remove,
120 NULL,
121 };
122
123 TESTSUITE_MAIN(tests);