diff --git a/Makefile b/Makefile
index c2a6098484..8d214286e0 100644
--- a/Makefile
+++ b/Makefile
@@ -825,8 +825,8 @@ TEST_BUILTINS_OBJS += test-env-helper.o
TEST_BUILTINS_OBJS += test-example-tap.o
TEST_BUILTINS_OBJS += test-find-pack.o
TEST_BUILTINS_OBJS += test-fsmonitor-client.o
+TEST_BUILTINS_OBJS += test-genbytes.o
TEST_BUILTINS_OBJS += test-genrandom.o
-TEST_BUILTINS_OBJS += test-genzeros.o
TEST_BUILTINS_OBJS += test-getcwd.o
TEST_BUILTINS_OBJS += test-hash-speed.o
TEST_BUILTINS_OBJS += test-hash.o
diff --git a/t/helper/meson.build b/t/helper/meson.build
index ae513b4cdc..f99688c49b 100644
--- a/t/helper/meson.build
+++ b/t/helper/meson.build
@@ -22,8 +22,8 @@ test_tool_sources = [
'test-example-tap.c',
'test-find-pack.c',
'test-fsmonitor-client.c',
+ 'test-genbytes.c',
'test-genrandom.c',
- 'test-genzeros.c',
'test-getcwd.c',
'test-hash-speed.c',
'test-hash.c',
diff --git a/t/helper/test-genbytes.c b/t/helper/test-genbytes.c
new file mode 100644
index 0000000000..b760326b24
--- /dev/null
+++ b/t/helper/test-genbytes.c
@@ -0,0 +1,61 @@
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
+#include "test-tool.h"
+#include "git-compat-util.h"
+#include "hex-ll.h"
+
+/*
+ * Write "count" copies of "byte" to stdout, or an endless stream of them if
+ * "count" is negative.
+ */
+static int generate_bytes(char byte, intmax_t count)
+{
+ char buf[256 * 1024];
+ ssize_t n;
+
+ memset(buf, byte, sizeof(buf));
+
+ /* Writing out individual bytes is slow... */
+ while (count < 0)
+ if (xwrite(1, buf, ARRAY_SIZE(buf)) < 0)
+ die_errno("write error");
+
+ while (count > 0) {
+ n = xwrite(1, buf,
+ count < ARRAY_SIZE(buf)
+ ? count : ARRAY_SIZE(buf));
+
+ if (n < 0)
+ die_errno("write error");
+
+ count -= n;
+ }
+
+ return 0;
+}
+
+static intmax_t parse_count(int argc, const char **argv, int pos)
+{
+ return pos < argc ? strtoimax(argv[pos], NULL, 0) : -1;
+}
+
+int cmd__genbytes(int argc, const char **argv)
+{
+ if (argc < 2 || argc > 3 || strlen(argv[1]) != 2 ||
+ strspn(argv[1], "0123456789abcdef") != 2) {
+ fprintf(stderr, "usage: %s <hex-byte> [<count>]\n", argv[0]);
+ return 1;
+ }
+
+ return generate_bytes(hex2chr(argv[1]), parse_count(argc, argv, 2));
+}
+
+int cmd__genzeros(int argc, const char **argv)
+{
+ if (argc > 2) {
+ fprintf(stderr, "usage: %s [<count>]\n", argv[0]);
+ return 1;
+ }
+
+ return generate_bytes('\0', parse_count(argc, argv, 1));
+}diff --git a/t/helper/test-genzeros.c b/t/helper/test-genzeros.c
deleted file mode 100644
index b895436a32..0000000000
--- a/t/helper/test-genzeros.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#define DISABLE_SIGN_COMPARE_WARNINGS
-
-#include "test-tool.h"
-#include "git-compat-util.h"
-
-int cmd__genzeros(int argc, const char **argv)
-{
- /* static, so that it is NUL-initialized */
- static const char zeros[256 * 1024];
- intmax_t count;
- ssize_t n;
-
- if (argc > 2) {
- fprintf(stderr, "usage: %s [<count>]\n", argv[0]);
- return 1;
- }
-
- count = argc > 1 ? strtoimax(argv[1], NULL, 0) : -1;
-
- /* Writing out individual NUL bytes is slow... */
- while (count < 0)
- if (xwrite(1, zeros, ARRAY_SIZE(zeros)) < 0)
- die_errno("write error");
-
- while (count > 0) {
- n = xwrite(1, zeros,
- count < ARRAY_SIZE(zeros)
- ? count : ARRAY_SIZE(zeros));
-
- if (n < 0)
- die_errno("write error");
-
- count -= n;
- }
-
- return 0;
-}diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index b71a22b43b..af70e2bec7 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -33,6 +33,7 @@ static struct test_cmd cmds[] = {
{ "example-tap", cmd__example_tap },
{ "find-pack", cmd__find_pack },
{ "fsmonitor-client", cmd__fsmonitor_client },
+ { "genbytes", cmd__genbytes },
{ "genrandom", cmd__genrandom },
{ "genzeros", cmd__genzeros },
{ "getcwd", cmd__getcwd },diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index f2885b33d5..c35e7412af 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -26,6 +26,7 @@ int cmd__env_helper(int argc, const char **argv);
int cmd__example_tap(int argc, const char **argv);
int cmd__find_pack(int argc, const char **argv);
int cmd__fsmonitor_client(int argc, const char **argv);
+int cmd__genbytes(int argc, const char **argv);
int cmd__genrandom(int argc, const char **argv);
int cmd__genzeros(int argc, const char **argv);
int cmd__getcwd(int argc, const char **argv);
diff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh
index 0b27d75fe3..b2032a799d 100755
--- a/t/t0613-reftable-write-options.sh
+++ b/t/t0613-reftable-write-options.sh
@@ -146,7 +146,7 @@ test_expect_success 'small block size fails with large reflog message' '
(
cd repo &&
test_commit A &&
- test-tool genzeros 500 | tr "\000" "a" >logmsg &&
+ test-tool genbytes 61 500 >logmsg &&
cat >expect <<-EOF &&
fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large
EOFdiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 01b97c8888..aa51a70a34 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -1182,7 +1182,7 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit mes
'
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'set up huge commit' '
- test-tool genzeros 2147483649 | tr "\000" "1" >expect &&
+ test-tool genbytes 31 2147483649 >expect &&
huge_commit=$(git commit-tree -F expect HEAD^{tree})
'
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index aac139e6a0..3c2f83091c 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -9,9 +9,9 @@ test_description='git pack-object'
test_expect_success 'setup' '
rm -f .git/index* &&
- test-tool genzeros 4096 | tr "\000" "a" >a &&
- test-tool genzeros 4096 | tr "\000" "b" >b &&
- test-tool genzeros 4096 | tr "\000" "c" >c &&
+ test-tool genbytes 61 4096 >a &&
+ test-tool genbytes 62 4096 >b &&
+ test-tool genbytes 63 4096 >c &&
test-tool genrandom "seed a" 2097152 >a_big &&
test-tool genrandom "seed b" 2097152 >b_big &&
git update-index --add a a_big b b_big c &&
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index 75ca7a25da..f59b3a00a8 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -662,8 +662,7 @@ test_expect_success 'setup trace2' '
'
test_expect_success 'setup large log output' '
- test-tool genzeros 50000 |
- tr "\000" "a" |
+ test-tool genbytes 61 50000 |
sed "s/a/this is a long commit message/g" >commit-msg &&
git commit --allow-empty -F commit-msg
'
diff --git a/t/t9850-shell.sh b/t/t9850-shell.sh
index 27cc49bbd1..cf05944682 100755
--- a/t/t9850-shell.sh
+++ b/t/t9850-shell.sh
@@ -30,7 +30,7 @@ test_expect_success 'shell allows interactive command' '
'
test_expect_success 'shell complains of overlong commands' '
- test-tool genzeros | tr "\000" "a" |
+ test-tool genbytes 61 |
test_must_fail git shell 2>err &&
test_grep "too long" err
'
--
gitgitgadget