2 * A test helper to exercise the progress display.
4 * Reads instructions from standard input, one instruction per line:
6 * "start <total>[ <title>]" - Call start_progress(title, total),
7 * Uses the default title of "Working hard"
8 * if the " <title>" is omitted.
9 * "progress <items>" - Call display_progress() with the given item count
11 * "throughput <bytes> <millis> - Call display_throughput() with the given
12 * byte count as parameter. The 'millis'
13 * specify the time elapsed since the
14 * start_progress() call.
15 * "update" - Set the 'progress_update' flag.
16 * "stop" - Call stop_progress().
18 * See 't0500-progress-display.sh' for examples.
20 #define GIT_TEST_PROGRESS_ONLY
21 #include "test-tool.h"
22 #include "parse-options.h"
25 #include "string-list.h"
27 int cmd__progress(int argc
, const char **argv
)
29 const char *const default_title
= "Working hard";
30 struct string_list titles
= STRING_LIST_INIT_DUP
;
31 struct strbuf line
= STRBUF_INIT
;
32 struct progress
*progress
= NULL
;
34 const char *usage
[] = {
35 "test-tool progress <stdin",
38 struct option options
[] = {
42 argc
= parse_options(argc
, argv
, NULL
, options
, usage
, 0);
44 usage_with_options(usage
, options
);
47 while (strbuf_getline(&line
, stdin
) != EOF
) {
50 if (skip_prefix(line
.buf
, "start ", (const char **) &end
)) {
51 uint64_t total
= strtoull(end
, &end
, 10);
55 * We can't use "end + 1" as an argument to
56 * start_progress(), it doesn't xstrdup() its
57 * "title" argument. We need to hold onto a
58 * valid "char *" for it until the end.
61 title
= default_title
;
63 title
= string_list_insert(&titles
, end
+ 1)->string
;
65 die("invalid input: '%s'\n", line
.buf
);
67 progress
= start_progress(title
, total
);
68 } else if (skip_prefix(line
.buf
, "progress ", (const char **) &end
)) {
69 uint64_t item_count
= strtoull(end
, &end
, 10);
71 die("invalid input: '%s'\n", line
.buf
);
72 display_progress(progress
, item_count
);
73 } else if (skip_prefix(line
.buf
, "throughput ",
74 (const char **) &end
)) {
75 uint64_t byte_count
, test_ms
;
77 byte_count
= strtoull(end
, &end
, 10);
79 die("invalid input: '%s'\n", line
.buf
);
80 test_ms
= strtoull(end
+ 1, &end
, 10);
82 die("invalid input: '%s'\n", line
.buf
);
83 progress_test_ns
= test_ms
* 1000 * 1000;
84 display_throughput(progress
, byte_count
);
85 } else if (!strcmp(line
.buf
, "update")) {
86 progress_test_force_update();
87 } else if (!strcmp(line
.buf
, "stop")) {
88 stop_progress(&progress
);
90 die("invalid input: '%s'\n", line
.buf
);
93 strbuf_release(&line
);
94 string_list_clear(&titles
, 0);