]>
Commit | Line | Data |
---|---|---|
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 | |
9b51e13b LDM |
26 | #include <shared/macro.h> |
27 | ||
f357866d | 28 | #include <libkmod/libkmod.h> |
eebca81e LDM |
29 | |
30 | #include "testsuite.h" | |
31 | ||
d96ca9c4 | 32 | static noreturn int test_initlib(const struct test *t) |
eebca81e LDM |
33 | { |
34 | struct kmod_ctx *ctx; | |
35 | const char *null_config = NULL; | |
36 | ||
37 | ctx = kmod_new(NULL, &null_config); | |
38 | if (ctx == NULL) | |
39 | exit(EXIT_FAILURE); | |
40 | ||
41 | kmod_unref(ctx); | |
42 | ||
43 | exit(EXIT_SUCCESS); | |
44 | } | |
f1155c15 | 45 | DEFINE_TEST(test_initlib, |
c5d81989 | 46 | .description = "test if libkmod's init function work"); |
53646fc5 | 47 | |
d96ca9c4 | 48 | static noreturn int test_insert(const struct test *t) |
53646fc5 LDM |
49 | { |
50 | struct kmod_ctx *ctx; | |
51 | struct kmod_module *mod; | |
52 | const char *null_config = NULL; | |
53 | int err; | |
54 | ||
55 | ctx = kmod_new(NULL, &null_config); | |
56 | if (ctx == NULL) | |
57 | exit(EXIT_FAILURE); | |
58 | ||
1669be85 | 59 | err = kmod_module_new_from_path(ctx, "/mod-simple.ko", &mod); |
53646fc5 LDM |
60 | if (err != 0) { |
61 | ERR("could not create module from path: %m\n"); | |
62 | exit(EXIT_FAILURE); | |
63 | } | |
64 | ||
65 | err = kmod_module_insert_module(mod, 0, NULL); | |
66 | if (err != 0) { | |
67 | ERR("could not insert module: %m\n"); | |
68 | exit(EXIT_FAILURE); | |
69 | } | |
70 | kmod_unref(ctx); | |
71 | ||
72 | exit(EXIT_SUCCESS); | |
73 | } | |
f1155c15 | 74 | DEFINE_TEST(test_insert, |
53646fc5 | 75 | .description = "test if libkmod's insert_module returns ok", |
53646fc5 | 76 | .config = { |
ada97199 | 77 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/", |
53646fc5 LDM |
78 | [TC_INIT_MODULE_RETCODES] = "bla:1:20", |
79 | }, | |
1669be85 | 80 | .modules_loaded = "mod_simple", |
c5d81989 | 81 | .need_spawn = true); |
eebca81e | 82 | |
d96ca9c4 | 83 | static noreturn int test_remove(const struct test *t) |
f6ef5d6b LDM |
84 | { |
85 | struct kmod_ctx *ctx; | |
1669be85 | 86 | struct kmod_module *mod_simple, *mod_bla; |
f6ef5d6b LDM |
87 | const char *null_config = NULL; |
88 | int err; | |
89 | ||
90 | ctx = kmod_new(NULL, &null_config); | |
91 | if (ctx == NULL) | |
92 | exit(EXIT_FAILURE); | |
93 | ||
1669be85 | 94 | err = kmod_module_new_from_name(ctx, "mod-simple", &mod_simple); |
9b51e13b LDM |
95 | if (err != 0) { |
96 | ERR("could not create module from name: %s\n", strerror(-err)); | |
97 | exit(EXIT_FAILURE); | |
98 | } | |
99 | ||
100 | err = kmod_module_new_from_name(ctx, "bla", &mod_bla); | |
f6ef5d6b | 101 | if (err != 0) { |
9b51e13b | 102 | ERR("could not create module from name: %s\n", strerror(-err)); |
f6ef5d6b LDM |
103 | exit(EXIT_FAILURE); |
104 | } | |
105 | ||
1669be85 | 106 | err = kmod_module_remove_module(mod_simple, 0); |
f6ef5d6b | 107 | if (err != 0) { |
9b51e13b | 108 | ERR("could not remove module: %s\n", strerror(-err)); |
f6ef5d6b LDM |
109 | exit(EXIT_FAILURE); |
110 | } | |
9b51e13b LDM |
111 | |
112 | err = kmod_module_remove_module(mod_bla, 0); | |
113 | if (err != -ENOENT) { | |
114 | ERR("wrong return code for failure test: %d\n", err); | |
115 | exit(EXIT_FAILURE); | |
116 | } | |
117 | ||
f6ef5d6b LDM |
118 | kmod_unref(ctx); |
119 | ||
120 | exit(EXIT_SUCCESS); | |
121 | } | |
f1155c15 | 122 | DEFINE_TEST(test_remove, |
f6ef5d6b | 123 | .description = "test if libkmod's remove_module returns ok", |
f6ef5d6b | 124 | .config = { |
ada97199 | 125 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-remove/", |
9b51e13b | 126 | [TC_DELETE_MODULE_RETCODES] = |
1669be85 | 127 | "mod-simple:0:0:bla:-1:" STRINGIFY(ENOENT), |
f6ef5d6b | 128 | }, |
c5d81989 | 129 | .need_spawn = true); |
f6ef5d6b | 130 | |
43289820 | 131 | TESTSUITE_MAIN(); |