1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/*
* Copyright (C) 2012-2013 ProFUSION embedded systems
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <inttypes.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libkmod/libkmod.h>
#include "testsuite.h"
static int loaded_1(const struct test *t)
{
struct kmod_ctx *ctx;
const char *null_config = NULL;
struct kmod_list *list, *itr;
int err;
ctx = kmod_new(NULL, &null_config);
if (ctx == NULL)
exit(EXIT_FAILURE);
err = kmod_module_new_from_loaded(ctx, &list);
if (err < 0) {
fprintf(stderr, "%s\n", strerror(-err));
kmod_unref(ctx);
exit(EXIT_FAILURE);
}
printf("Module Size Used by\n");
kmod_list_foreach(itr, list) {
struct kmod_module *mod = kmod_module_get_module(itr);
const char *name = kmod_module_get_name(mod);
int use_count = kmod_module_get_refcnt(mod);
long size = kmod_module_get_size(mod);
struct kmod_list *holders, *hitr;
int first = 1;
printf("%-19s %8ld %d ", name, size, use_count);
holders = kmod_module_get_holders(mod);
kmod_list_foreach(hitr, holders) {
struct kmod_module *hm = kmod_module_get_module(hitr);
if (!first)
putchar(',');
else
first = 0;
fputs(kmod_module_get_name(hm), stdout);
kmod_module_unref(hm);
}
putchar('\n');
kmod_module_unref_list(holders);
kmod_module_unref(mod);
}
kmod_module_unref_list(list);
kmod_unref(ctx);
return EXIT_SUCCESS;
}
DEFINE_TEST(loaded_1,
.description = "check if list of module is created",
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-loaded/",
},
.need_spawn = true,
.output = {
.out = TESTSUITE_ROOTFS "test-loaded/correct.txt",
});
TESTSUITE_MAIN();
|