]>
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 | ||
61e9433f LDM |
18 | #include <stdio.h> |
19 | #include <stdlib.h> | |
20 | #include <stddef.h> | |
21 | #include <errno.h> | |
22 | #include <unistd.h> | |
23 | #include <inttypes.h> | |
24 | #include <string.h> | |
25 | #include <libkmod.h> | |
26 | ||
27 | #include "testsuite.h" | |
28 | ||
29 | static int loaded_1(const struct test *t) | |
30 | { | |
31 | struct kmod_ctx *ctx; | |
32 | const char *null_config = NULL; | |
33 | struct kmod_list *list, *itr; | |
34 | int err; | |
35 | ||
36 | ctx = kmod_new(NULL, &null_config); | |
37 | if (ctx == NULL) | |
38 | exit(EXIT_FAILURE); | |
39 | ||
40 | err = kmod_module_new_from_loaded(ctx, &list); | |
41 | if (err < 0) { | |
42 | fprintf(stderr, "%s\n", strerror(-err)); | |
43 | kmod_unref(ctx); | |
44 | exit(EXIT_FAILURE); | |
45 | } | |
46 | ||
47 | printf("Module Size Used by\n"); | |
48 | ||
49 | kmod_list_foreach(itr, list) { | |
50 | struct kmod_module *mod = kmod_module_get_module(itr); | |
51 | const char *name = kmod_module_get_name(mod); | |
52 | int use_count = kmod_module_get_refcnt(mod); | |
53 | long size = kmod_module_get_size(mod); | |
54 | struct kmod_list *holders, *hitr; | |
55 | int first = 1; | |
56 | ||
57 | printf("%-19s %8ld %d ", name, size, use_count); | |
58 | holders = kmod_module_get_holders(mod); | |
59 | kmod_list_foreach(hitr, holders) { | |
60 | struct kmod_module *hm = kmod_module_get_module(hitr); | |
61 | ||
62 | if (!first) | |
63 | putchar(','); | |
64 | else | |
65 | first = 0; | |
66 | ||
67 | fputs(kmod_module_get_name(hm), stdout); | |
68 | kmod_module_unref(hm); | |
69 | } | |
70 | putchar('\n'); | |
71 | kmod_module_unref_list(holders); | |
72 | kmod_module_unref(mod); | |
73 | } | |
74 | kmod_module_unref_list(list); | |
75 | ||
76 | kmod_unref(ctx); | |
77 | ||
78 | return EXIT_SUCCESS; | |
79 | } | |
c5d81989 | 80 | static DEFINE_TEST(loaded_1, |
61e9433f | 81 | .description = "check if list of module is created", |
61e9433f LDM |
82 | .config = { |
83 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-loaded/", | |
84 | }, | |
85 | .need_spawn = true, | |
86 | .output = { | |
87 | .stdout = TESTSUITE_ROOTFS "test-loaded/correct.txt", | |
c5d81989 | 88 | }); |
61e9433f LDM |
89 | |
90 | static const struct test *tests[] = { | |
91 | &sloaded_1, | |
92 | NULL, | |
93 | }; | |
94 | ||
e9fa9de3 | 95 | TESTSUITE_MAIN(tests); |