]>
Commit | Line | Data |
---|---|---|
e701e381 LDM |
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 | ||
eebca81e LDM |
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 | ||
53646fc5 | 28 | static int test_initlib(const struct test *t) |
eebca81e LDM |
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 | } | |
c5d81989 LDM |
41 | static DEFINE_TEST(test_initlib, |
42 | .description = "test if libkmod's init function work"); | |
53646fc5 LDM |
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 | } | |
c5d81989 | 70 | static DEFINE_TEST(test_insert, |
53646fc5 | 71 | .description = "test if libkmod's insert_module returns ok", |
53646fc5 LDM |
72 | .config = { |
73 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modinfo/", | |
74 | [TC_INIT_MODULE_RETCODES] = "bla:1:20", | |
75 | }, | |
c5d81989 | 76 | .need_spawn = true); |
eebca81e | 77 | |
f6ef5d6b LDM |
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 | } | |
c5d81989 | 104 | static DEFINE_TEST(test_remove, |
f6ef5d6b | 105 | .description = "test if libkmod's remove_module returns ok", |
f6ef5d6b LDM |
106 | .config = { |
107 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modinfo/", | |
108 | [TC_DELETE_MODULE_RETCODES] = "bla:1:20", | |
109 | }, | |
c5d81989 | 110 | .need_spawn = true); |
f6ef5d6b | 111 | |
eebca81e | 112 | static const struct test *tests[] = { |
53646fc5 LDM |
113 | &stest_initlib, |
114 | &stest_insert, | |
f6ef5d6b | 115 | &stest_remove, |
eebca81e LDM |
116 | NULL, |
117 | }; | |
118 | ||
e9fa9de3 | 119 | TESTSUITE_MAIN(tests); |