summaryrefslogtreecommitdiffstats
path: root/shlibs/mount/src/test.c
diff options
context:
space:
mode:
authorKarel Zak2009-11-27 00:33:37 +0100
committerKarel Zak2010-06-03 15:20:10 +0200
commitc12cec75b09a9dc8711d4323fda017a0b77f1105 (patch)
treede503fcb48bbcc8b80c12b6a386331304e1fe216 /shlibs/mount/src/test.c
parentlibmount: add basic utils (diff)
downloadkernel-qcow2-util-linux-c12cec75b09a9dc8711d4323fda017a0b77f1105.tar.gz
kernel-qcow2-util-linux-c12cec75b09a9dc8711d4323fda017a0b77f1105.tar.xz
kernel-qcow2-util-linux-c12cec75b09a9dc8711d4323fda017a0b77f1105.zip
libmount: add debug support
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/test.c')
-rw-r--r--shlibs/mount/src/test.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/shlibs/mount/src/test.c b/shlibs/mount/src/test.c
new file mode 100644
index 000000000..eb4f2d1d0
--- /dev/null
+++ b/shlibs/mount/src/test.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ *
+ * Routines for TEST_PROGRAMs
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#ifndef TEST_PROGRAM
+#define TEST_PROGRAM
+#endif
+
+#include "mountP.h"
+
+int mnt_run_test(struct mtest *tests, int argc, char *argv[])
+{
+ int rc = -1;
+ struct mtest *ts;
+
+ assert(tests);
+ assert(argc);
+ assert(argv);
+
+ if (argc < 2 ||
+ strcmp(argv[1], "--help") == 0 ||
+ strcmp(argv[1], "-h") == 0)
+ goto usage;
+
+ mnt_init_debug(0);
+
+ for (ts = tests; ts->name; ts++) {
+ if (strcmp(ts->name, argv[1]) == 0) {
+ rc = ts->body(ts, argc - 1, argv + 1);
+ if (rc)
+ printf("FAILED [rc=%d]", rc);
+ break;
+ }
+ }
+
+ if (rc == -1 && ts->name == NULL)
+ goto usage;
+
+ return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+usage:
+ printf("\nUsage:\n\t%s <test> [testoptions]\nTests:\n",
+ program_invocation_short_name);
+ for (ts = tests; ts->name; ts++) {
+ printf("\t%-15s", ts->name);
+ if (ts->usage)
+ printf(" %s\n", ts->usage);
+ }
+ printf("\n");
+ return EXIT_FAILURE;
+}