blob: b7afd718c0df1a9f81aba507a96fd2cbfe0d6c49 [file] [log] [blame]
Pedro Pedruzzi760b8962012-01-28 03:22:47 -02001/*
2 * Copyright (C) 2012 ProFUSION embedded systems
3 * Copyright (C) 2012 Pedro Pedruzzi
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <libkmod.h>
23
24#include "libkmod-util.h"
25#include "testsuite.h"
26
27static int alias_1(const struct test *t)
28{
29 static const char *input[] = {
30 "test1234",
31 "test[abcfoobar]2211",
32 "bar[aaa][bbbb]sss",
33 "kmod[p.b]lib",
34 "[az]1234[AZ]",
35 NULL,
36 };
37
38 char buf[PATH_MAX];
39 size_t len;
40 const char **alias;
41
42 for (alias = input; *alias != NULL; alias++) {
43 int ret;
44
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020045 ret = alias_normalize(*alias, buf, &len);
46 printf("input %s\n", *alias);
47 printf("return %d\n", ret);
48
49 if (ret == 0) {
50 printf("len %zu\n", len);
51 printf("output %s\n", buf);
52 }
53
54 printf("\n");
55 }
56
57 return EXIT_SUCCESS;
58}
59static const struct test salias_1 = {
60 .name = "alias_1",
61 .description = "check if alias_normalize does the right thing",
62 .func = alias_1,
63 .config = {
64 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-alias/",
65 },
66 .need_spawn = true,
67 .output = {
68 .stdout = TESTSUITE_ROOTFS "test-alias/correct.txt",
69 },
70};
71
72static const struct test *tests[] = {
73 &salias_1,
74 NULL,
75};
76
77int main(int argc, char *argv[])
78{
79 const struct test *t;
80 int arg;
81 size_t i;
82
83 arg = test_init(argc, argv, tests);
84 if (arg == 0)
85 return 0;
86
87 if (arg < argc) {
88 t = test_find(tests, argv[arg]);
89 if (t == NULL) {
90 fprintf(stderr, "could not find test %s\n", argv[arg]);
91 exit(EXIT_FAILURE);
92 }
93
94 return test_run(t);
95 }
96
97 for (i = 0; tests[i] != NULL; i++) {
98 if (test_run(tests[i]) != 0)
99 exit(EXIT_FAILURE);
100 }
101
102 exit(EXIT_SUCCESS);
103}