]> git.ipfire.org Git - thirdparty/kmod.git/blob - testsuite/test-new-module.c
1658422abcbb59c85d3d571d32f8c111ec6ca17e
[thirdparty/kmod.git] / testsuite / test-new-module.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 int from_name(const struct test *t)
32 {
33 static const char *modnames[] = {
34 "ext4",
35 "balbalbalbbalbalbalbalbalbalbal",
36 "snd-hda-intel",
37 "snd-timer",
38 "iTCO_wdt",
39 NULL,
40 };
41 const char **p;
42 struct kmod_ctx *ctx;
43 struct kmod_module *mod;
44 const char *null_config = NULL;
45 int err;
46
47 ctx = kmod_new(NULL, &null_config);
48 if (ctx == NULL)
49 exit(EXIT_FAILURE);
50
51 for (p = modnames; p != NULL; p++) {
52 err = kmod_module_new_from_name(ctx, *p, &mod);
53 if (err < 0)
54 exit(EXIT_SUCCESS);
55
56 printf("modname: %s\n", kmod_module_get_name(mod));
57 kmod_module_unref(mod);
58 }
59
60 kmod_unref(ctx);
61
62 return EXIT_SUCCESS;
63 }
64 static DEFINE_TEST(from_name,
65 .description = "check if module names are parsed correctly",
66 .config = {
67 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-new-module/from_name/",
68 },
69 .need_spawn = true,
70 .output = {
71 .out = TESTSUITE_ROOTFS "test-new-module/from_name/correct.txt",
72 });
73
74 static int from_alias(const struct test *t)
75 {
76 static const char *modnames[] = {
77 "ext4.*",
78 NULL,
79 };
80 const char **p;
81 struct kmod_ctx *ctx;
82 int err;
83
84 ctx = kmod_new(NULL, NULL);
85 if (ctx == NULL)
86 exit(EXIT_FAILURE);
87
88 for (p = modnames; p != NULL; p++) {
89 struct kmod_list *l, *list = NULL;
90
91 err = kmod_module_new_from_lookup(ctx, *p, &list);
92 if (err < 0)
93 exit(EXIT_SUCCESS);
94
95 kmod_list_foreach(l, list) {
96 struct kmod_module *m;
97 m = kmod_module_get_module(l);
98
99 printf("modname: %s\n", kmod_module_get_name(m));
100 kmod_module_unref(m);
101 }
102 kmod_module_unref_list(list);
103 }
104
105 kmod_unref(ctx);
106
107 return EXIT_SUCCESS;
108 }
109 static DEFINE_TEST(from_alias,
110 .description = "check if aliases are parsed correctly",
111 .config = {
112 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-new-module/from_alias/",
113 },
114 .need_spawn = true,
115 .output = {
116 .out = TESTSUITE_ROOTFS "test-new-module/from_alias/correct.txt",
117 });
118
119 static const struct test *tests[] = {
120 &sfrom_name,
121 &sfrom_alias,
122 NULL,
123 };
124
125 TESTSUITE_MAIN(tests);