mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
2b6f6ea1bd
In 't0500-progress-display.sh' all tests running 'test-tool progress --total=<N>' fail on big-endian systems, e.g. like this: + test-tool progress --total=3 Working hard [...] + test_i18ncmp expect out --- expect 2019-10-18 23:07:54.765523916 +0000 +++ out 2019-10-18 23:07:54.773523916 +0000 @@ -1,4 +1,2 @@ -Working hard: 33% (1/3)<CR> -Working hard: 66% (2/3)<CR> -Working hard: 100% (3/3)<CR> -Working hard: 100% (3/3), done. +Working hard: 0% (1/12884901888)<CR> +Working hard: 0% (3/12884901888), done. The reason for that bogus value is that '--total's parameter is parsed via parse-options's OPT_INTEGER into a uint64_t variable [1], so the two bits of 3 end up in the "wrong" bytes on big-endian systems (12884901888 = 0x300000000). Change the type of that variable from uint64_t to int, to match what parse-options expects; in the tests of the progress output we won't use values that don't fit into an int anyway. [1] start_progress() expects the total number as an uint64_t, that's why I chose the same type when declaring the variable holding the value given on the command line. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> [jpag: Debian unstable/ppc64 (big-endian)] Tested-By: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> [tz: Fedora s390x (big-endian)] Tested-By: Todd Zullinger <tmz@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
81 lines
2.3 KiB
C
81 lines
2.3 KiB
C
/*
|
|
* 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)
|
|
{
|
|
int 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;
|
|
}
|