Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'progress.c' has seen a few fixes recently [1], and, unfortunately, some of those fixes required further fixes [2]. It seems it's time to have a few tests focusing on the subtleties of the progress display. Add the 'test-tool progress' subcommand to help testing the progress display, reading instructions from standard input and turning them into calls to the display_progress() and display_throughput() functions with the given parameters. The progress display is, however, critically dependent on timing, because it's only updated once every second or, if the toal is known in advance, every 1%, and there is the throughput rate as well. These make the progress display far too undeterministic for testing as-is. To address this, add a few testing-specific variables and functions to 'progress.c', allowing the the new test helper to: - Disable the triggered-every-second SIGALRM and set the 'progress_update' flag explicitly based in the input instructions. This way the progress line will be updated deterministically when the test wants it to be updated. - Specify the time elapsed since start_progress() to make the throughput rate calculations deterministic. Add the new test script 't0500-progress-display.sh' to check a few simple cases with and without throughput, and that a shorter progress line properly covers up the previously displayed line in different situations. [1] See commits 545dc34 (progress: break too long progress bar lines, 2019-04-12) and 9f1fd84 (progress: clear previous progress update dynamically, 2019-04-12). [2] 1aed1a5 (progress: avoid empty line when breaking the progress line, 2019-05-19) Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
Showing
6 changed files
with
400 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* A test helper to exercise the progress display. | ||
* | ||
* Reads instructions from standard input, one instruction per line: | ||
* | ||
* "progress <items>" - Call display_progress() with the given item count | ||
* as parameter. | ||
* "throughput <bytes> <millis> - Call display_throughput() with the given | ||
* byte count as parameter. The 'millis' | ||
* specify the time elapsed since the | ||
* start_progress() call. | ||
* "update" - Set the 'progress_update' flag. | ||
* | ||
* See 't0500-progress-display.sh' for examples. | ||
*/ | ||
#include "test-tool.h" | ||
#include "gettext.h" | ||
#include "parse-options.h" | ||
#include "progress.h" | ||
#include "strbuf.h" | ||
|
||
/* | ||
* These are defined in 'progress.c', but are not exposed in 'progress.h', | ||
* because they are exclusively for testing. | ||
*/ | ||
extern int progress_testing; | ||
extern uint64_t progress_test_ns; | ||
void progress_test_force_update(void); | ||
|
||
int cmd__progress(int argc, const char **argv) | ||
{ | ||
uint64_t total = 0; | ||
const char *title; | ||
struct strbuf line = STRBUF_INIT; | ||
struct progress *progress; | ||
|
||
const char *usage[] = { | ||
"test-tool progress [--total=<n>] <progress-title>", | ||
NULL | ||
}; | ||
struct option options[] = { | ||
OPT_INTEGER(0, "total", &total, "total number of items"), | ||
OPT_END(), | ||
}; | ||
|
||
argc = parse_options(argc, argv, NULL, options, usage, 0); | ||
if (argc != 1) | ||
die("need a title for the progress output"); | ||
title = argv[0]; | ||
|
||
progress_testing = 1; | ||
progress = start_progress(title, total); | ||
while (strbuf_getline(&line, stdin) != EOF) { | ||
char *end; | ||
|
||
if (skip_prefix(line.buf, "progress ", (const char **) &end)) { | ||
uint64_t item_count = strtoull(end, &end, 10); | ||
if (*end != '\0') | ||
die("invalid input: '%s'\n", line.buf); | ||
display_progress(progress, item_count); | ||
} else if (skip_prefix(line.buf, "throughput ", | ||
(const char **) &end)) { | ||
uint64_t byte_count, test_ms; | ||
|
||
byte_count = strtoull(end, &end, 10); | ||
if (*end != ' ') | ||
die("invalid input: '%s'\n", line.buf); | ||
test_ms = strtoull(end + 1, &end, 10); | ||
if (*end != '\0') | ||
die("invalid input: '%s'\n", line.buf); | ||
progress_test_ns = test_ms * 1000 * 1000; | ||
display_throughput(progress, byte_count); | ||
} else if (!strcmp(line.buf, "update")) | ||
progress_test_force_update(); | ||
else | ||
die("invalid input: '%s'\n", line.buf); | ||
} | ||
stop_progress(&progress); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.