2 * A test helper to exercise the progress display.
4 * Reads instructions from standard input, one instruction per line:
6 * "progress <items>" - Call display_progress() with the given item count
8 * "throughput <bytes> <millis> - Call display_throughput() with the given
9 * byte count as parameter. The 'millis'
10 * specify the time elapsed since the
11 * start_progress() call.
12 * "update" - Set the 'progress_update' flag.
14 * See 't0500-progress-display.sh' for examples.
16 #define GIT_TEST_PROGRESS_ONLY
17 #include "test-tool.h"
19 #include "parse-options.h"
23 int cmd__progress(int argc, const char **argv)
27 struct strbuf line = STRBUF_INIT;
28 struct progress *progress;
30 const char *usage[] = {
31 "test-tool progress [--total=<n>] <progress-title>",
34 struct option options[] = {
35 OPT_INTEGER(0, "total", &total, "total number of items"),
39 argc = parse_options(argc, argv, NULL, options, usage, 0);
41 die("need a title for the progress output");
45 progress = start_progress(title, total);
46 while (strbuf_getline(&line, stdin) != EOF) {
49 if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
50 uint64_t item_count = strtoull(end, &end, 10);
52 die("invalid input: '%s'\n", line.buf);
53 display_progress(progress, item_count);
54 } else if (skip_prefix(line.buf, "throughput ",
55 (const char **) &end)) {
56 uint64_t byte_count, test_ms;
58 byte_count = strtoull(end, &end, 10);
60 die("invalid input: '%s'\n", line.buf);
61 test_ms = strtoull(end + 1, &end, 10);
63 die("invalid input: '%s'\n", line.buf);
64 progress_test_ns = test_ms * 1000 * 1000;
65 display_throughput(progress, byte_count);
66 } else if (!strcmp(line.buf, "update"))
67 progress_test_force_update();
69 die("invalid input: '%s'\n", line.buf);
71 stop_progress(&progress);