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