]>
Commit | Line | Data |
---|---|---|
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, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
18 | #include <errno.h> | |
19 | #include <inttypes.h> | |
20 | #include <stddef.h> | |
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
24 | #include <unistd.h> | |
25 | ||
26 | #include <libkmod.h> | |
27 | ||
28 | #include "testsuite.h" | |
29 | ||
30 | static noreturn int test_initlib(const struct test *t) | |
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 | } | |
43 | DEFINE_TEST(test_initlib, | |
44 | .description = "test if libkmod's init function work"); | |
45 | ||
46 | static noreturn int test_insert(const struct test *t) | |
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 | } | |
72 | DEFINE_TEST(test_insert, | |
73 | .description = "test if libkmod's insert_module returns ok", | |
74 | .config = { | |
75 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/", | |
76 | [TC_INIT_MODULE_RETCODES] = "bla:1:20", | |
77 | }, | |
78 | .modules_loaded = "ext4", | |
79 | .need_spawn = true); | |
80 | ||
81 | static noreturn int test_remove(const struct test *t) | |
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 | } | |
107 | DEFINE_TEST(test_remove, | |
108 | .description = "test if libkmod's remove_module returns ok", | |
109 | .config = { | |
110 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-remove/", | |
111 | [TC_DELETE_MODULE_RETCODES] = "bla:1:20", | |
112 | }, | |
113 | .need_spawn = true); | |
114 | ||
115 | TESTSUITE_MAIN(); |