summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-09-01 17:03:19 +0100
committerRichard Jones <rjones@redhat.com>2010-09-01 17:03:19 +0100
commit8c37961b455cbc72d4879da65c6aafd332857f05 (patch)
tree3b6973a4268253feeb22760c4114ca4a82087743
parent99679fe5a28efcee3be2406aeaf446b4e1a976df (diff)
downloadlibguestfs-8c37961b455cbc72d4879da65c6aafd332857f05.tar.gz
libguestfs-8c37961b455cbc72d4879da65c6aafd332857f05.tar.xz
libguestfs-8c37961b455cbc72d4879da65c6aafd332857f05.zip
debug: Add 'debug progress' command.
This debugging command generates progress notification messages, used for testing purposes.
-rw-r--r--daemon/debug.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/daemon/debug.c b/daemon/debug.c
index 9df4dc21..bca6b9f6 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -56,6 +56,7 @@ static char *debug_env (const char *subcmd, int argc, char *const *const argv);
static char *debug_fds (const char *subcmd, int argc, char *const *const argv);
static char *debug_ls (const char *subcmd, int argc, char *const *const argv);
static char *debug_ll (const char *subcmd, int argc, char *const *const argv);
+static char *debug_progress (const char *subcmd, int argc, char *const *const argv);
static char *debug_segv (const char *subcmd, int argc, char *const *const argv);
static char *debug_sh (const char *subcmd, int argc, char *const *const argv);
@@ -66,6 +67,7 @@ static struct cmd cmds[] = {
{ "fds", debug_fds },
{ "ls", debug_ls },
{ "ll", debug_ll },
+ { "progress", debug_progress },
{ "segv", debug_segv },
{ "sh", debug_sh },
{ NULL, NULL }
@@ -332,6 +334,37 @@ debug_ll (const char *subcmd, int argc, char *const *const argv)
return out;
}
+/* Generate progress notification messages in order to test progress bars. */
+static char *
+debug_progress (const char *subcmd, int argc, char *const *const argv)
+{
+ if (argc < 1) {
+ error:
+ reply_with_error ("progress: expecting arg (time in seconds as string)");
+ return NULL;
+ }
+
+ char *secs_str = argv[0];
+ unsigned secs;
+ if (sscanf (secs_str, "%u", &secs) != 1 || secs == 0)
+ goto error;
+
+ unsigned i;
+ unsigned tsecs = secs * 10; /* 1/10ths of seconds */
+ for (i = 1; i <= tsecs; ++i) {
+ usleep (100000);
+ notify_progress ((uint64_t) i, (uint64_t) tsecs);
+ }
+
+ char *ret = strdup ("ok");
+ if (ret == NULL) {
+ reply_with_perror ("strdup");
+ return NULL;
+ }
+
+ return ret;
+}
+
/* Enable core dumping to the given core pattern.
* Note that this pattern is relative to any chroot of the process which
* crashes. This means that if you want to write the core file to the guest's