]>
Commit | Line | Data |
---|---|---|
2c37ca7c | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c12cec75 | 2 | /* |
2c37ca7c KZ |
3 | * This file is part of libmount from util-linux project. |
4 | * | |
5 | * Copyright (C) 2010-2018 Karel Zak <kzak@redhat.com> | |
6 | * | |
7 | * libmount is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU Lesser General Public License as published by | |
9 | * the Free Software Foundation; either version 2.1 of the License, or | |
10 | * (at your option) any later version. | |
c12cec75 | 11 | * |
c12cec75 KZ |
12 | * |
13 | * Routines for TEST_PROGRAMs | |
14 | */ | |
15 | ||
16 | #include <stdlib.h> | |
17 | #include <string.h> | |
18 | #include <errno.h> | |
19 | ||
20 | #ifndef TEST_PROGRAM | |
21 | #define TEST_PROGRAM | |
22 | #endif | |
23 | ||
24 | #include "mountP.h" | |
25 | ||
68164f6c | 26 | int mnt_run_test(struct libmnt_test *tests, int argc, char *argv[]) |
c12cec75 KZ |
27 | { |
28 | int rc = -1; | |
68164f6c | 29 | struct libmnt_test *ts; |
c12cec75 KZ |
30 | |
31 | assert(tests); | |
32 | assert(argc); | |
33 | assert(argv); | |
34 | ||
35 | if (argc < 2 || | |
36 | strcmp(argv[1], "--help") == 0 || | |
37 | strcmp(argv[1], "-h") == 0) | |
38 | goto usage; | |
39 | ||
40 | mnt_init_debug(0); | |
41 | ||
42 | for (ts = tests; ts->name; ts++) { | |
43 | if (strcmp(ts->name, argv[1]) == 0) { | |
44 | rc = ts->body(ts, argc - 1, argv + 1); | |
45 | if (rc) | |
46 | printf("FAILED [rc=%d]", rc); | |
47 | break; | |
48 | } | |
49 | } | |
50 | ||
abc3d154 | 51 | if (rc < 0 && ts->name == NULL) |
c12cec75 KZ |
52 | goto usage; |
53 | ||
54 | return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; | |
55 | usage: | |
56 | printf("\nUsage:\n\t%s <test> [testoptions]\nTests:\n", | |
57 | program_invocation_short_name); | |
58 | for (ts = tests; ts->name; ts++) { | |
59 | printf("\t%-15s", ts->name); | |
60 | if (ts->usage) | |
61 | printf(" %s\n", ts->usage); | |
62 | } | |
63 | printf("\n"); | |
64 | return EXIT_FAILURE; | |
65 | } |