]>
git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-progress.c
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"
23 #include "parse-options.h"
26 #include "string-list.h"
28 int cmd__progress(int argc
, const char **argv
)
30 const char *const default_title
= "Working hard";
31 struct string_list titles
= STRING_LIST_INIT_DUP
;
32 struct strbuf line
= STRBUF_INIT
;
33 struct progress
*progress
= NULL
;
35 const char *usage
[] = {
36 "test-tool progress <stdin",
39 struct option options
[] = {
43 argc
= parse_options(argc
, argv
, NULL
, options
, usage
, 0);
45 usage_with_options(usage
, options
);
48 while (strbuf_getline(&line
, stdin
) != EOF
) {
51 if (skip_prefix(line
.buf
, "start ", (const char **) &end
)) {
52 uint64_t total
= strtoull(end
, &end
, 10);
56 * We can't use "end + 1" as an argument to
57 * start_progress(), it doesn't xstrdup() its
58 * "title" argument. We need to hold onto a
59 * valid "char *" for it until the end.
62 title
= default_title
;
64 title
= string_list_insert(&titles
, end
+ 1)->string
;
66 die("invalid input: '%s'\n", line
.buf
);
68 progress
= start_progress(title
, total
);
69 } else if (skip_prefix(line
.buf
, "progress ", (const char **) &end
)) {
70 uint64_t item_count
= strtoull(end
, &end
, 10);
72 die("invalid input: '%s'\n", line
.buf
);
73 display_progress(progress
, item_count
);
74 } else if (skip_prefix(line
.buf
, "throughput ",
75 (const char **) &end
)) {
76 uint64_t byte_count
, test_ms
;
78 byte_count
= strtoull(end
, &end
, 10);
80 die("invalid input: '%s'\n", line
.buf
);
81 test_ms
= strtoull(end
+ 1, &end
, 10);
83 die("invalid input: '%s'\n", line
.buf
);
84 progress_test_ns
= test_ms
* 1000 * 1000;
85 display_throughput(progress
, byte_count
);
86 } else if (!strcmp(line
.buf
, "update")) {
87 progress_test_force_update();
88 } else if (!strcmp(line
.buf
, "stop")) {
89 stop_progress(&progress
);
91 die("invalid input: '%s'\n", line
.buf
);
94 strbuf_release(&line
);
95 string_list_clear(&titles
, 0);