]>
Commit | Line | Data |
---|---|---|
e701e381 | 1 | /* |
e6b0e49b | 2 | * Copyright (C) 2012-2013 ProFUSION embedded systems |
e701e381 | 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. | |
e701e381 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. | |
e701e381 | 13 | * |
e1b1ab24 | 14 | * You should have received a copy of the GNU Lesser General Public |
dea2dfee | 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
e701e381 LDM |
16 | */ |
17 | ||
61e9433f | 18 | #include <errno.h> |
61e9433f | 19 | #include <inttypes.h> |
c2e4286b LDM |
20 | #include <stddef.h> |
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
61e9433f | 23 | #include <string.h> |
c2e4286b LDM |
24 | #include <unistd.h> |
25 | ||
61e9433f LDM |
26 | #include <libkmod.h> |
27 | ||
28 | #include "testsuite.h" | |
29 | ||
30 | static int loaded_1(const struct test *t) | |
31 | { | |
32 | struct kmod_ctx *ctx; | |
33 | const char *null_config = NULL; | |
34 | struct kmod_list *list, *itr; | |
35 | int err; | |
36 | ||
37 | ctx = kmod_new(NULL, &null_config); | |
38 | if (ctx == NULL) | |
39 | exit(EXIT_FAILURE); | |
40 | ||
41 | err = kmod_module_new_from_loaded(ctx, &list); | |
42 | if (err < 0) { | |
43 | fprintf(stderr, "%s\n", strerror(-err)); | |
44 | kmod_unref(ctx); | |
45 | exit(EXIT_FAILURE); | |
46 | } | |
47 | ||
48 | printf("Module Size Used by\n"); | |
49 | ||
50 | kmod_list_foreach(itr, list) { | |
51 | struct kmod_module *mod = kmod_module_get_module(itr); | |
52 | const char *name = kmod_module_get_name(mod); | |
53 | int use_count = kmod_module_get_refcnt(mod); | |
54 | long size = kmod_module_get_size(mod); | |
55 | struct kmod_list *holders, *hitr; | |
56 | int first = 1; | |
57 | ||
58 | printf("%-19s %8ld %d ", name, size, use_count); | |
59 | holders = kmod_module_get_holders(mod); | |
60 | kmod_list_foreach(hitr, holders) { | |
61 | struct kmod_module *hm = kmod_module_get_module(hitr); | |
62 | ||
63 | if (!first) | |
64 | putchar(','); | |
65 | else | |
66 | first = 0; | |
67 | ||
68 | fputs(kmod_module_get_name(hm), stdout); | |
69 | kmod_module_unref(hm); | |
70 | } | |
71 | putchar('\n'); | |
72 | kmod_module_unref_list(holders); | |
73 | kmod_module_unref(mod); | |
74 | } | |
75 | kmod_module_unref_list(list); | |
76 | ||
77 | kmod_unref(ctx); | |
78 | ||
79 | return EXIT_SUCCESS; | |
80 | } | |
f1155c15 | 81 | DEFINE_TEST(loaded_1, |
61e9433f | 82 | .description = "check if list of module is created", |
61e9433f LDM |
83 | .config = { |
84 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-loaded/", | |
85 | }, | |
86 | .need_spawn = true, | |
87 | .output = { | |
bd4e7340 | 88 | .out = TESTSUITE_ROOTFS "test-loaded/correct.txt", |
c5d81989 | 89 | }); |
61e9433f | 90 | |
43289820 | 91 | TESTSUITE_MAIN(); |