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 |
Lucas De Marchi | dea2dfe | 2014-12-25 23:32:03 -0200 | [diff] [blame] | 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
Lucas De Marchi | e701e38 | 2012-01-26 17:01:41 -0200 | [diff] [blame] | 16 | */ |
| 17 | |
Lucas De Marchi | c2e4286 | 2014-10-03 01:41:42 -0300 | [diff] [blame] | 18 | #include <errno.h> |
| 19 | #include <inttypes.h> |
| 20 | #include <stddef.h> |
Lucas De Marchi | 61e9433 | 2012-01-25 18:16:45 -0200 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
Lucas De Marchi | 61e9433 | 2012-01-25 18:16:45 -0200 | [diff] [blame] | 23 | #include <string.h> |
Lucas De Marchi | c2e4286 | 2014-10-03 01:41:42 -0300 | [diff] [blame] | 24 | #include <unistd.h> |
| 25 | |
Lucas De Marchi | f357866 | 2015-01-02 12:38:27 -0200 | [diff] [blame] | 26 | #include <libkmod/libkmod.h> |
Lucas De Marchi | 61e9433 | 2012-01-25 18:16:45 -0200 | [diff] [blame] | 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 | f1155c1 | 2014-10-09 13:00:30 -0300 | [diff] [blame] | 81 | 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 = { |
John Spencer | bd4e734 | 2013-08-27 01:38:11 +0200 | [diff] [blame] | 88 | .out = 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 | |
Lucas De Marchi | 4328982 | 2014-10-09 14:29:04 -0300 | [diff] [blame] | 91 | TESTSUITE_MAIN(); |