blob: 360065cbef72a0971f2b40ab8aae8f9679e7a809 [file] [log] [blame]
Lucas De Marchia9474302012-01-29 15:43:19 -02001/*
Lucas De Marchie6b0e492013-01-16 11:27:21 -02002 * Copyright (C) 2012-2013 ProFUSION embedded systems
Lucas De Marchia9474302012-01-29 15:43:19 -02003 *
Lucas De Marchie1b1ab22012-07-10 09:42:24 -03004 * 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 Marchia9474302012-01-29 15:43:19 -02008 *
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 Marchie1b1ab22012-07-10 09:42:24 -030011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
Lucas De Marchia9474302012-01-29 15:43:19 -020013 *
Lucas De Marchie1b1ab22012-07-10 09:42:24 -030014 * You should have received a copy of the GNU Lesser General Public
Lucas De Marchidea2dfe2014-12-25 23:32:03 -020015 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Lucas De Marchia9474302012-01-29 15:43:19 -020016 */
17
Lucas De Marchic2e42862014-10-03 01:41:42 -030018#include <errno.h>
19#include <inttypes.h>
20#include <stddef.h>
Lucas De Marchia9474302012-01-29 15:43:19 -020021#include <stdio.h>
22#include <stdlib.h>
Lucas De Marchia9474302012-01-29 15:43:19 -020023#include <string.h>
Lucas De Marchic2e42862014-10-03 01:41:42 -030024#include <unistd.h>
25
Lucas De Marchif3578662015-01-02 12:38:27 -020026#include <libkmod/libkmod.h>
Lucas De Marchia9474302012-01-29 15:43:19 -020027
28#include "testsuite.h"
29
30static 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 Marchif1155c12014-10-09 13:00:30 -030063DEFINE_TEST(from_name,
Lucas De Marchia9474302012-01-29 15:43:19 -020064 .description = "check if module names are parsed correctly",
Lucas De Marchia9474302012-01-29 15:43:19 -020065 .config = {
66 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-new-module/from_name/",
67 },
68 .need_spawn = true,
69 .output = {
John Spencerbd4e7342013-08-27 01:38:11 +020070 .out = TESTSUITE_ROOTFS "test-new-module/from_name/correct.txt",
Lucas De Marchic5d81982012-02-07 10:46:46 -020071 });
Lucas De Marchidfdfb962012-01-29 16:02:20 -020072
73static 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 Marchif1155c12014-10-09 13:00:30 -0300108DEFINE_TEST(from_alias,
Lucas De Marchidfdfb962012-01-29 16:02:20 -0200109 .description = "check if aliases are parsed correctly",
Lucas De Marchidfdfb962012-01-29 16:02:20 -0200110 .config = {
111 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-new-module/from_alias/",
112 },
113 .need_spawn = true,
114 .output = {
John Spencerbd4e7342013-08-27 01:38:11 +0200115 .out = TESTSUITE_ROOTFS "test-new-module/from_alias/correct.txt",
Lucas De Marchic5d81982012-02-07 10:46:46 -0200116 });
Lucas De Marchidfdfb962012-01-29 16:02:20 -0200117
Lucas De Marchi43289822014-10-09 14:29:04 -0300118TESTSUITE_MAIN();