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 #include "test-tool.h"
18 #include "parse-options.h"
23 * These are defined in 'progress.c', but are not exposed in 'progress.h',
24 * because they are exclusively for testing.
26 extern int progress_testing
;
27 extern uint64_t progress_test_ns
;
28 void progress_test_force_update(void);
30 int cmd__progress(int argc
, const char **argv
)
34 struct strbuf line
= STRBUF_INIT
;
35 struct progress
*progress
;
37 const char *usage
[] = {
38 "test-tool progress [--total=<n>] <progress-title>",
41 struct option options
[] = {
42 OPT_INTEGER(0, "total", &total
, "total number of items"),
46 argc
= parse_options(argc
, argv
, NULL
, options
, usage
, 0);
48 die("need a title for the progress output");
52 progress
= start_progress(title
, total
);
53 while (strbuf_getline(&line
, stdin
) != EOF
) {
56 if (skip_prefix(line
.buf
, "progress ", (const char **) &end
)) {
57 uint64_t item_count
= strtoull(end
, &end
, 10);
59 die("invalid input: '%s'\n", line
.buf
);
60 display_progress(progress
, item_count
);
61 } else if (skip_prefix(line
.buf
, "throughput ",
62 (const char **) &end
)) {
63 uint64_t byte_count
, test_ms
;
65 byte_count
= strtoull(end
, &end
, 10);
67 die("invalid input: '%s'\n", line
.buf
);
68 test_ms
= strtoull(end
+ 1, &end
, 10);
70 die("invalid input: '%s'\n", line
.buf
);
71 progress_test_ns
= test_ms
* 1000 * 1000;
72 display_throughput(progress
, byte_count
);
73 } else if (!strcmp(line
.buf
, "update"))
74 progress_test_force_update();
76 die("invalid input: '%s'\n", line
.buf
);
78 stop_progress(&progress
);