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)
--- /dev/null
+/*
+ * 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
/* 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
--- /dev/null
+/*
+ * 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;
+}