Lucas De Marchi | a947430 | 2012-01-29 15:43:19 -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 | a947430 | 2012-01-29 15:43:19 -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 | a947430 | 2012-01-29 15:43:19 -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 | a947430 | 2012-01-29 15:43:19 -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 | a947430 | 2012-01-29 15:43:19 -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 | a947430 | 2012-01-29 15:43:19 -0200 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
Lucas De Marchi | a947430 | 2012-01-29 15:43:19 -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 | a947430 | 2012-01-29 15:43:19 -0200 | [diff] [blame] | 27 | |
| 28 | #include "testsuite.h" |
| 29 | |
| 30 | static int from_name(const struct test *t) |
| 31 | { |
| 32 | static const char *modnames[] = { |
| 33 | "ext4", |
| 34 | "balbalbalbbalbalbalbalbalbalbal", |
| 35 | "snd-hda-intel", |
| 36 | "snd-timer", |
| 37 | "iTCO_wdt", |
| 38 | NULL, |
| 39 | }; |
| 40 | const char **p; |
| 41 | struct kmod_ctx *ctx; |
| 42 | struct kmod_module *mod; |
| 43 | const char *null_config = NULL; |
| 44 | int err; |
| 45 | |
| 46 | ctx = kmod_new(NULL, &null_config); |
| 47 | if (ctx == NULL) |
| 48 | exit(EXIT_FAILURE); |
| 49 | |
| 50 | for (p = modnames; p != NULL; p++) { |
| 51 | err = kmod_module_new_from_name(ctx, *p, &mod); |
| 52 | if (err < 0) |
| 53 | exit(EXIT_SUCCESS); |
| 54 | |
| 55 | printf("modname: %s\n", kmod_module_get_name(mod)); |
| 56 | kmod_module_unref(mod); |
| 57 | } |
| 58 | |
| 59 | kmod_unref(ctx); |
| 60 | |
| 61 | return EXIT_SUCCESS; |
| 62 | } |
Lucas De Marchi | f1155c1 | 2014-10-09 13:00:30 -0300 | [diff] [blame] | 63 | DEFINE_TEST(from_name, |
Lucas De Marchi | a947430 | 2012-01-29 15:43:19 -0200 | [diff] [blame] | 64 | .description = "check if module names are parsed correctly", |
Lucas De Marchi | a947430 | 2012-01-29 15:43:19 -0200 | [diff] [blame] | 65 | .config = { |
| 66 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-new-module/from_name/", |
| 67 | }, |
| 68 | .need_spawn = true, |
| 69 | .output = { |
John Spencer | bd4e734 | 2013-08-27 01:38:11 +0200 | [diff] [blame] | 70 | .out = TESTSUITE_ROOTFS "test-new-module/from_name/correct.txt", |
Lucas De Marchi | c5d8198 | 2012-02-07 10:46:46 -0200 | [diff] [blame] | 71 | }); |
Lucas De Marchi | dfdfb96 | 2012-01-29 16:02:20 -0200 | [diff] [blame] | 72 | |
| 73 | static int from_alias(const struct test *t) |
| 74 | { |
| 75 | static const char *modnames[] = { |
| 76 | "ext4.*", |
| 77 | NULL, |
| 78 | }; |
| 79 | const char **p; |
| 80 | struct kmod_ctx *ctx; |
| 81 | int err; |
| 82 | |
| 83 | ctx = kmod_new(NULL, NULL); |
| 84 | if (ctx == NULL) |
| 85 | exit(EXIT_FAILURE); |
| 86 | |
| 87 | for (p = modnames; p != NULL; p++) { |
| 88 | struct kmod_list *l, *list = NULL; |
| 89 | |
| 90 | err = kmod_module_new_from_lookup(ctx, *p, &list); |
| 91 | if (err < 0) |
| 92 | exit(EXIT_SUCCESS); |
| 93 | |
| 94 | kmod_list_foreach(l, list) { |
| 95 | struct kmod_module *m; |
| 96 | m = kmod_module_get_module(l); |
| 97 | |
| 98 | printf("modname: %s\n", kmod_module_get_name(m)); |
| 99 | kmod_module_unref(m); |
| 100 | } |
| 101 | kmod_module_unref_list(list); |
| 102 | } |
| 103 | |
| 104 | kmod_unref(ctx); |
| 105 | |
| 106 | return EXIT_SUCCESS; |
| 107 | } |
Lucas De Marchi | f1155c1 | 2014-10-09 13:00:30 -0300 | [diff] [blame] | 108 | DEFINE_TEST(from_alias, |
Lucas De Marchi | dfdfb96 | 2012-01-29 16:02:20 -0200 | [diff] [blame] | 109 | .description = "check if aliases are parsed correctly", |
Lucas De Marchi | dfdfb96 | 2012-01-29 16:02:20 -0200 | [diff] [blame] | 110 | .config = { |
| 111 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-new-module/from_alias/", |
| 112 | }, |
| 113 | .need_spawn = true, |
| 114 | .output = { |
John Spencer | bd4e734 | 2013-08-27 01:38:11 +0200 | [diff] [blame] | 115 | .out = TESTSUITE_ROOTFS "test-new-module/from_alias/correct.txt", |
Lucas De Marchi | c5d8198 | 2012-02-07 10:46:46 -0200 | [diff] [blame] | 116 | }); |
Lucas De Marchi | dfdfb96 | 2012-01-29 16:02:20 -0200 | [diff] [blame] | 117 | |
Lucas De Marchi | 4328982 | 2014-10-09 14:29:04 -0300 | [diff] [blame] | 118 | TESTSUITE_MAIN(); |