summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--shlibs/mount/src/Makefile.am4
-rw-r--r--shlibs/mount/src/init.c31
-rw-r--r--shlibs/mount/src/mountP.h32
-rw-r--r--shlibs/mount/src/test.c59
4 files changed, 123 insertions, 3 deletions
diff --git a/shlibs/mount/src/Makefile.am b/shlibs/mount/src/Makefile.am
index 2ac06bd35..0483367a3 100644
--- a/shlibs/mount/src/Makefile.am
+++ b/shlibs/mount/src/Makefile.am
@@ -11,9 +11,7 @@ nodist_mountinc_HEADERS = mount.h
usrlib_exec_LTLIBRARIES = libmount.la
libmount_la_SOURCES = $(mountinc_HEADERS)
-nodist_libmount_la_SOURCES = mount.h \
- version.c \
- utils.c
+nodist_libmount_la_SOURCES = mount.h version.c utils.c test.c init.c
libmount_la_LIBADD = $(ul_libblkid_la)
diff --git a/shlibs/mount/src/init.c b/shlibs/mount/src/init.c
new file mode 100644
index 000000000..33da47b5c
--- /dev/null
+++ b/shlibs/mount/src/init.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+
+#include <stdlib.h>
+
+#include "mountP.h"
+
+#ifdef CONFIG_LIBMOUNT_DEBUG
+int libmount_debug_mask;
+
+void mnt_init_debug(int mask)
+{
+ if (libmount_debug_mask & DEBUG_INIT)
+ return;
+ if (!mask) {
+ char *str = mnt_getenv_safe("LIBMOUNT_DEBUG");
+ if (str)
+ libmount_debug_mask = strtoul(str, 0, 0);
+ } else
+ libmount_debug_mask = mask;
+
+ if (libmount_debug_mask)
+ printf("libmount: debug mask set to 0x%04x.\n",
+ libmount_debug_mask);
+ libmount_debug_mask |= DEBUG_INIT;
+}
+#endif
diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h
index 172341349..5ac3b6bc0 100644
--- a/shlibs/mount/src/mountP.h
+++ b/shlibs/mount/src/mountP.h
@@ -16,11 +16,43 @@
/* features */
#define CONFIG_CDROM_NOMEDIUM_RETRIES 5
#define CONFIG_LIBMOUNT_ASSERT
+#define CONFIG_LIBMOUNT_DEBUG
#ifdef CONFIG_LIBMOUNT_ASSERT
#include <assert.h>
#endif
+/*
+ * Debug
+ */
+#if defined(TEST_PROGRAM) && !defined(LIBMOUNT_DEBUG)
+#define CONFIG_LIBMOUNT_DEBUG
+#endif
+
+#define DEBUG_INIT (1 << 1)
+#define DEBUG_ALL 0xFFFF
+
+#ifdef CONFIG_LIBMOUNT_DEBUG
+#include <stdio.h>
+extern int libmount_debug_mask;
+extern void mnt_init_debug(int mask);
+#define DBG(m,x) if ((m) & libmount_debug_mask) x;
+#else
+#define DBG(m,x)
+#define mnt_init_debug(x)
+#endif
+
+#ifdef TEST_PROGRAM
+struct mtest {
+ const char *name;
+ int (*body)(struct mtest *ts, int argc, char *argv[]);
+ const char *usage;
+};
+
+/* utils.c */
+extern int mnt_run_test(struct mtest *tests, int argc, char *argv[]);
+#endif
+
/* utils.c */
extern char *mnt_getenv_safe(const char *arg);
#ifndef HAVE_STRNLEN
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;
+}