| 1 |
/* |
| 2 |
* Copyright (C) 2008-2009 Karel Zak <[email protected]> |
| 3 |
* |
| 4 |
* This file may be redistributed under the terms of the |
| 5 |
* GNU Lesser General Public License. |
| 6 |
* |
| 7 |
* Routines for TEST_PROGRAMs |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <stdlib.h> |
| 11 |
#include <string.h> |
| 12 |
#include <errno.h> |
| 13 |
|
| 14 |
#ifndef TEST_PROGRAM |
| 15 |
#define TEST_PROGRAM |
| 16 |
#endif |
| 17 |
|
| 18 |
#include "fdiskP.h" |
| 19 |
|
| 20 |
int fdisk_run_test(struct fdisk_test *tests, int argc, char *argv[]) |
| 21 |
{ |
| 22 |
int rc = -1; |
| 23 |
struct fdisk_test *ts; |
| 24 |
|
| 25 |
assert(tests); |
| 26 |
assert(argc); |
| 27 |
assert(argv); |
| 28 |
|
| 29 |
if (argc < 2 || |
| 30 |
strcmp(argv[1], "--help") == 0 || |
| 31 |
strcmp(argv[1], "-h") == 0) |
| 32 |
goto usage; |
| 33 |
|
| 34 |
fdisk_init_debug(0); |
| 35 |
|
| 36 |
for (ts = tests; ts->name; ts++) { |
| 37 |
if (strcmp(ts->name, argv[1]) == 0) { |
| 38 |
rc = ts->body(ts, argc - 1, argv + 1); |
| 39 |
if (rc) |
| 40 |
printf("FAILED [rc=%d]", rc); |
| 41 |
break; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
if (rc < 0 && ts->name == NULL) |
| 46 |
goto usage; |
| 47 |
|
| 48 |
return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 49 |
usage: |
| 50 |
printf("\nUsage:\n\t%s <test> [testoptions]\nTests:\n", |
| 51 |
program_invocation_short_name); |
| 52 |
for (ts = tests; ts->name; ts++) { |
| 53 |
printf("\t%-15s", ts->name); |
| 54 |
if (ts->usage) |
| 55 |
printf(" %s\n", ts->usage); |
| 56 |
} |
| 57 |
printf("\n"); |
| 58 |
return EXIT_FAILURE; |
| 59 |
} |