Skip to content

Commit d5cfd14

Browse files
dschogitster
authored andcommitted
tests: teach the test-tool to generate NUL bytes and use it
In cc95bc2 (t5562: replace /dev/zero with a pipe from generate_zero_bytes, 2019-02-09), we replaced usage of /dev/zero (which is not available on NonStop, apparently) by a Perl script snippet to generate NUL bytes. Sadly, it does not seem to work on NonStop, as t5562 reportedly hangs. Worse, this also hangs in the Ubuntu 16.04 agents of the CI builds on Azure Pipelines: for some reason, the Perl script snippet that is run via `generate_zero_bytes` in t5562's 'CONTENT_LENGTH overflow ssite_t' test case tries to write out an infinite amount of NUL bytes unless a broken pipe is encountered, that snippet never encounters the broken pipe, and keeps going until the build times out. Oddly enough, this does not reproduce on the Windows and macOS agents, nor in a local Ubuntu 18.04. This developer tried for a day to figure out the exact circumstances under which this hang happens, to no avail, the details remain a mystery. In the end, though, what counts is that this here change incidentally fixes that hang (maybe also on NonStop?). Even more positively, it gets rid of yet another unnecessary Perl invocation. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d991948 commit d5cfd14

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
740740
TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
741741
TEST_BUILTINS_OBJS += test-example-decorate.o
742742
TEST_BUILTINS_OBJS += test-genrandom.o
743+
TEST_BUILTINS_OBJS += test-genzeros.o
743744
TEST_BUILTINS_OBJS += test-hash.o
744745
TEST_BUILTINS_OBJS += test-hashmap.o
745746
TEST_BUILTINS_OBJS += test-hash-speed.o

t/helper/test-genzeros.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "test-tool.h"
2+
#include "git-compat-util.h"
3+
4+
int cmd__genzeros(int argc, const char **argv)
5+
{
6+
long count;
7+
8+
if (argc > 2) {
9+
fprintf(stderr, "usage: %s [<count>]\n", argv[0]);
10+
return 1;
11+
}
12+
13+
count = argc > 1 ? strtol(argv[1], NULL, 0) : -1L;
14+
15+
while (count < 0 || count--) {
16+
if (putchar(0) == EOF)
17+
return -1;
18+
}
19+
20+
return 0;
21+
}

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static struct test_cmd cmds[] = {
1919
{ "dump-untracked-cache", cmd__dump_untracked_cache },
2020
{ "example-decorate", cmd__example_decorate },
2121
{ "genrandom", cmd__genrandom },
22+
{ "genzeros", cmd__genzeros },
2223
{ "hashmap", cmd__hashmap },
2324
{ "hash-speed", cmd__hash_speed },
2425
{ "index-version", cmd__index_version },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int cmd__dump_split_index(int argc, const char **argv);
1616
int cmd__dump_untracked_cache(int argc, const char **argv);
1717
int cmd__example_decorate(int argc, const char **argv);
1818
int cmd__genrandom(int argc, const char **argv);
19+
int cmd__genzeros(int argc, const char **argv);
1920
int cmd__hashmap(int argc, const char **argv);
2021
int cmd__hash_speed(int argc, const char **argv);
2122
int cmd__index_version(int argc, const char **argv);

t/test-lib-functions.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,7 @@ remove_cr () {
120120
# If $1 is 'infinity', output forever or until the receiving pipe stops reading,
121121
# whichever comes first.
122122
generate_zero_bytes () {
123-
perl -e 'if ($ARGV[0] == "infinity") {
124-
while (-1) {
125-
print "\0"
126-
}
127-
} else {
128-
print "\0" x $ARGV[0]
129-
}' "$@"
123+
test-tool genzeros "$@"
130124
}
131125

132126
# In some bourne shell implementations, the "unset" builtin returns

0 commit comments

Comments
 (0)