]>
Commit | Line | Data |
---|---|---|
a9474303 | 1 | /* |
e6b0e49b | 2 | * Copyright (C) 2012-2013 ProFUSION embedded systems |
a9474303 | 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. | |
a9474303 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. | |
a9474303 | 13 | * |
e1b1ab24 LDM |
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 | |
a9474303 LDM |
17 | */ |
18 | ||
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
21 | #include <stddef.h> | |
22 | #include <errno.h> | |
23 | #include <unistd.h> | |
24 | #include <inttypes.h> | |
25 | #include <string.h> | |
26 | #include <libkmod.h> | |
27 | ||
28 | #include "testsuite.h" | |
29 | ||
30 | static int from_name(const struct test *t) | |
31 | { | |
32 | static const char *modnames[] = { | |
33 | "ext4", | |
34 | "balbalbalbbalbalbalbalbalbalbal", | |
35 | "snd-hda-intel", | |
36 | "snd-timer", | |
37 | "iTCO_wdt", | |
38 | NULL, | |
39 | }; | |
40 | const char **p; | |
41 | struct kmod_ctx *ctx; | |
42 | struct kmod_module *mod; | |
43 | const char *null_config = NULL; | |
44 | int err; | |
45 | ||
46 | ctx = kmod_new(NULL, &null_config); | |
47 | if (ctx == NULL) | |
48 | exit(EXIT_FAILURE); | |
49 | ||
50 | for (p = modnames; p != NULL; p++) { | |
51 | err = kmod_module_new_from_name(ctx, *p, &mod); | |
52 | if (err < 0) | |
53 | exit(EXIT_SUCCESS); | |
54 | ||
55 | printf("modname: %s\n", kmod_module_get_name(mod)); | |
56 | kmod_module_unref(mod); | |
57 | } | |
58 | ||
59 | kmod_unref(ctx); | |
60 | ||
61 | return EXIT_SUCCESS; | |
62 | } | |
c5d81989 | 63 | static DEFINE_TEST(from_name, |
a9474303 | 64 | .description = "check if module names are parsed correctly", |
a9474303 LDM |
65 | .config = { |
66 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-new-module/from_name/", | |
67 | }, | |
68 | .need_spawn = true, | |
69 | .output = { | |
bd4e7340 | 70 | .out = TESTSUITE_ROOTFS "test-new-module/from_name/correct.txt", |
c5d81989 | 71 | }); |
dfdfb962 LDM |
72 | |
73 | static int from_alias(const struct test *t) | |
74 | { | |
75 | static const char *modnames[] = { | |
76 | "ext4.*", | |
77 | NULL, | |
78 | }; | |
79 | const char **p; | |
80 | struct kmod_ctx *ctx; | |
81 | int err; | |
82 | ||
83 | ctx = kmod_new(NULL, NULL); | |
84 | if (ctx == NULL) | |
85 | exit(EXIT_FAILURE); | |
86 | ||
87 | for (p = modnames; p != NULL; p++) { | |
88 | struct kmod_list *l, *list = NULL; | |
89 | ||
90 | err = kmod_module_new_from_lookup(ctx, *p, &list); | |
91 | if (err < 0) | |
92 | exit(EXIT_SUCCESS); | |
93 | ||
94 | kmod_list_foreach(l, list) { | |
95 | struct kmod_module *m; | |
96 | m = kmod_module_get_module(l); | |
97 | ||
98 | printf("modname: %s\n", kmod_module_get_name(m)); | |
99 | kmod_module_unref(m); | |
100 | } | |
101 | kmod_module_unref_list(list); | |
102 | } | |
103 | ||
104 | kmod_unref(ctx); | |
105 | ||
106 | return EXIT_SUCCESS; | |
107 | } | |
c5d81989 | 108 | static DEFINE_TEST(from_alias, |
dfdfb962 | 109 | .description = "check if aliases are parsed correctly", |
dfdfb962 LDM |
110 | .config = { |
111 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-new-module/from_alias/", | |
112 | }, | |
113 | .need_spawn = true, | |
114 | .output = { | |
bd4e7340 | 115 | .out = TESTSUITE_ROOTFS "test-new-module/from_alias/correct.txt", |
c5d81989 | 116 | }); |
dfdfb962 | 117 | |
a9474303 LDM |
118 | static const struct test *tests[] = { |
119 | &sfrom_name, | |
dfdfb962 | 120 | &sfrom_alias, |
a9474303 LDM |
121 | NULL, |
122 | }; | |
123 | ||
e9fa9de3 | 124 | TESTSUITE_MAIN(tests); |