Lucas De Marchi | e701e38 | 2012-01-26 17:01:41 -0200 | [diff] [blame] | 1 | /* |
Lucas De Marchi | e6b0e49 | 2013-01-16 11:27:21 -0200 | [diff] [blame] | 2 | * Copyright (C) 2012-2013 ProFUSION embedded systems |
Lucas De Marchi | e701e38 | 2012-01-26 17:01:41 -0200 | [diff] [blame] | 3 | * |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 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. |
Lucas De Marchi | e701e38 | 2012-01-26 17:01:41 -0200 | [diff] [blame] | 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 |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
Lucas De Marchi | e701e38 | 2012-01-26 17:01:41 -0200 | [diff] [blame] | 13 | * |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 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 |
Lucas De Marchi | e701e38 | 2012-01-26 17:01:41 -0200 | [diff] [blame] | 17 | */ |
| 18 | |
Lucas De Marchi | 61e9433 | 2012-01-25 18:16:45 -0200 | [diff] [blame] | 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 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 | } |
Lucas De Marchi | c5d8198 | 2012-02-07 10:46:46 -0200 | [diff] [blame] | 81 | static DEFINE_TEST(loaded_1, |
Lucas De Marchi | 61e9433 | 2012-01-25 18:16:45 -0200 | [diff] [blame] | 82 | .description = "check if list of module is created", |
Lucas De Marchi | 61e9433 | 2012-01-25 18:16:45 -0200 | [diff] [blame] | 83 | .config = { |
| 84 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-loaded/", |
| 85 | }, |
| 86 | .need_spawn = true, |
| 87 | .output = { |
| 88 | .stdout = TESTSUITE_ROOTFS "test-loaded/correct.txt", |
Lucas De Marchi | c5d8198 | 2012-02-07 10:46:46 -0200 | [diff] [blame] | 89 | }); |
Lucas De Marchi | 61e9433 | 2012-01-25 18:16:45 -0200 | [diff] [blame] | 90 | |
| 91 | static const struct test *tests[] = { |
| 92 | &sloaded_1, |
| 93 | NULL, |
| 94 | }; |
| 95 | |
Lucas De Marchi | e9fa9de | 2012-02-07 10:09:20 -0200 | [diff] [blame] | 96 | TESTSUITE_MAIN(tests); |