Skip to content

Commit bc5d341

Browse files
committed
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]>
1 parent 2f7aa36 commit bc5d341

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
742742
TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
743743
TEST_BUILTINS_OBJS += test-example-decorate.o
744744
TEST_BUILTINS_OBJS += test-genrandom.o
745+
TEST_BUILTINS_OBJS += test-genzeros.o
745746
TEST_BUILTINS_OBJS += test-hash.o
746747
TEST_BUILTINS_OBJS += test-hashmap.o
747748
TEST_BUILTINS_OBJS += test-hash-speed.o

t/helper/test-genzeros.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}
22+

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static struct test_cmd cmds[] = {
2020
{ "dump-untracked-cache", cmd__dump_untracked_cache },
2121
{ "example-decorate", cmd__example_decorate },
2222
{ "genrandom", cmd__genrandom },
23+
{ "genzeros", cmd__genzeros },
2324
{ "hashmap", cmd__hashmap },
2425
{ "hash-speed", cmd__hash_speed },
2526
{ "iconv", cmd__iconv },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ int cmd__dump_split_index(int argc, const char **argv);
1717
int cmd__dump_untracked_cache(int argc, const char **argv);
1818
int cmd__example_decorate(int argc, const char **argv);
1919
int cmd__genrandom(int argc, const char **argv);
20+
int cmd__genzeros(int argc, const char **argv);
2021
int cmd__hashmap(int argc, const char **argv);
2122
int cmd__hash_speed(int argc, const char **argv);
2223
int cmd__iconv(int argc, const char **argv);

t/t5562-http-backend-content-length.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ test_expect_success GZIP 'push gzipped empty' '
143143

144144
test_expect_success 'CONTENT_LENGTH overflow ssite_t' '
145145
NOT_FIT_IN_SSIZE=$(ssize_b100dots) &&
146-
generate_zero_bytes infinity | env \
146+
generate_zero_bytes | env \
147147
CONTENT_TYPE=application/x-git-upload-pack-request \
148148
QUERY_STRING=/repo.git/git-upload-pack \
149149
PATH_TRANSLATED="$PWD"/.git/git-upload-pack \

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)