~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to libmount/src/test.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
 
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 "mountP.h"
 
19
 
 
20
int mnt_run_test(struct libmnt_test *tests, int argc, char *argv[])
 
21
{
 
22
        int rc = -1;
 
23
        struct libmnt_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
        mnt_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
}