[PATCH 3/3] t: replace "test-tool genzeros" with "genbytes NUL"
- From
Kristofer Karlsson via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Nov 7, 2026, 14:59 UTC
- Message-ID
- <169ca5968ea2aa40c26076697f8d5c83270f9888.1794063565.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2301.git.1794063565.gitgitgadget@gmail.com>
From: Kristofer Karlsson <krka@spotify.com>
Now that "genbytes" exists, "genzeros" is merely a special case of it for NUL bytes. It is only kept as a separate command because a NUL byte cannot be passed as a command-line argument.
Teach "genbytes" to accept "NUL" as the name of that byte instead, convert the remaining callers of "genzeros", and remove it, so that there is a single command for generating repeated bytes.
Only some of these callers depend on the data being NUL bytes, like t1007, which compares against the object ID of 5GB of zeros, and t5318, which zeroes out part of a commit-graph file. The others only care about the size, but keep generating NUL bytes there, too, so that what they test does not change.
Signed-off-by: Kristofer Karlsson <krka@spotify.com> --- t/helper/test-genbytes.c | 29 +++++++++++++++++------------ t/helper/test-tool.c | 1 - t/helper/test-tool.h | 1 - t/t1007-hash-object.sh | 8 ++++---- t/t1051-large-conversion.sh | 4 ++-- t/t1450-fsck.sh | 4 ++-- t/t4141-apply-too-large.sh | 2 +- t/t5318-commit-graph.sh | 2 +- 8 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/t/helper/test-genbytes.c b/t/helper/test-genbytes.c index 293af78d0d..ad0fb2d2b4 100644 --- a/t/helper/test-genbytes.c +++ b/t/helper/test-genbytes.c @@ -33,6 +33,19 @@ static int generate_bytes(char byte, intmax_t count) return 0; } +/* + * A NUL byte cannot be passed as an argument, so it is spelled out as + * "NUL". Returns -1 for anything that is not a single byte. + */ +static int parse_byte(const char *arg) +{ + if (!strcmp(arg, "NUL")) + return '\0'; + if (strlen(arg) == 1) + return (unsigned char)arg[0]; + return -1; +} + static intmax_t parse_count(int argc, const char **argv, int pos) { return pos < argc ? strtoimax(argv[pos], NULL, 0) : -1; @@ -40,20 +53,12 @@ static intmax_t parse_count(int argc, const char **argv, int pos) int cmd__genbytes(int argc, const char **argv) { - if (argc < 2 || argc > 3 || strlen(argv[1]) != 1) { - fprintf(stderr, "usage: %s <byte> [<count>]\n", argv[0]); - return 1; - } + int byte; - return generate_bytes(argv[1][0], parse_count(argc, argv, 2)); -} - -int cmd__genzeros(int argc, const char **argv) -{ - if (argc > 2) { - fprintf(stderr, "usage: %s [<count>]\n", argv[0]); + if (argc < 2 || argc > 3 || (byte = parse_byte(argv[1])) < 0) { + fprintf(stderr, "usage: %s (<byte> | NUL) [<count>]\n", argv[0]); return 1; } - return generate_bytes('\0', parse_count(argc, argv, 1)); + return generate_bytes(byte, parse_count(argc, argv, 2)); } diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index af70e2bec7..16571fd702 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -35,7 +35,6 @@ static struct test_cmd cmds[] = { { "fsmonitor-client", cmd__fsmonitor_client }, { "genbytes", cmd__genbytes }, { "genrandom", cmd__genrandom }, - { "genzeros", cmd__genzeros }, { "getcwd", cmd__getcwd }, { "hashmap", cmd__hashmap }, { "hash-speed", cmd__hash_speed }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index c35e7412af..1b45c8c37b 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -28,7 +28,6 @@ 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); int cmd__hashmap(int argc, const char **argv); int cmd__hash_speed(int argc, const char **argv); diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh index 463b38f990..ea1a1949a1 100755 --- a/t/t1007-hash-object.sh +++ b/t/t1007-hash-object.sh @@ -263,7 +263,7 @@ test_expect_success '--stdin outside of repository (uses default hash)' ' test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ 'files over 4GB hash literally' ' - test-tool genzeros $((5*1024*1024*1024)) >big && + test-tool genbytes NUL $((5*1024*1024*1024)) >big && test_oid large5GB >expect && git hash-object --stdin --literally <big >actual && test_cmp expect actual @@ -271,7 +271,7 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ 'files over 4GB hash correctly via --stdin' ' - { test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } && + { test -f big || test-tool genbytes NUL $((5*1024*1024*1024)) >big; } && test_oid large5GB >expect && git hash-object --stdin <big >actual && test_cmp expect actual @@ -279,7 +279,7 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ 'files over 4GB hash correctly' ' - { test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } && + { test -f big || test-tool genbytes NUL $((5*1024*1024*1024)) >big; } && test_oid large5GB >expect && git hash-object -- big >actual && test_cmp expect actual @@ -289,7 +289,7 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ # We ensure that cleaning doesn't mangle large files on 64-bit Windows. test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \ 'hash filtered files over 4GB correctly' ' - { test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } && + { test -f big || test-tool genbytes NUL $((5*1024*1024*1024)) >big; } && test_oid large5GB >expect && test_config filter.null-filter.clean "cat" && echo "big filter=null-filter" >.gitattributes && diff --git a/t/t1051-large-conversion.sh b/t/t1051-large-conversion.sh index 361afb679b..6364c396fd 100755 --- a/t/t1051-large-conversion.sh +++ b/t/t1051-large-conversion.sh @@ -91,7 +91,7 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \ test_commit test small "a small file" && small_size=$(test_file_size small) && test_config filter.makelarge.smudge \ - "test-tool genzeros $((5*1024*1024*1024)) && cat" && + "test-tool genbytes NUL $((5*1024*1024*1024)) && cat" && echo "small filter=makelarge" >.gitattributes && rm small && git checkout -- small && @@ -103,7 +103,7 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \ # the actual size, we ensure that cleaning doesn't mangle large files on 64-bit Windows. test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \ 'files over 4GB convert on input' ' - test-tool genzeros $((5*1024*1024*1024)) >big && + test-tool genbytes NUL $((5*1024*1024*1024)) >big && test_config filter.checklarge.clean "wc -c >big.size" && echo "big filter=checklarge" >.gitattributes && git add big && diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 3e9eb251cb..86b01d071c 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -1111,7 +1111,7 @@ test_expect_success 'fsck error on gitattributes with excessive line lengths' ' ' test_expect_success 'fsck error on gitattributes with excessive size' ' - blob=$(test-tool genzeros $((100 * 1024 * 1024 + 1)) | git hash-object -w --stdin) && + blob=$(test-tool genbytes NUL $((100 * 1024 * 1024 + 1)) | git hash-object -w --stdin) && test_when_finished "remove_object $blob" && tree=$(printf "100644 blob %s\t%s\n" $blob .gitattributes | git mktree) && test_when_finished "remove_object $tree" && @@ -1157,7 +1157,7 @@ test_expect_success 'fsck with blob size equal to core.bigFileThreshold' ' git init big-blob-fsck && ( cd big-blob-fsck && - test-tool genzeros 1024 >blob && + test-tool genbytes NUL 1024 >blob && git add blob && git commit -m "blob equal to threshold" && git repack -ad && diff --git a/t/t4141-apply-too-large.sh b/t/t4141-apply-too-large.sh index 6bc1c7a663..309807859c 100755 --- a/t/t4141-apply-too-large.sh +++ b/t/t4141-apply-too-large.sh @@ -13,7 +13,7 @@ test_expect_success EXPENSIVE 'git apply rejects patches that are too large' ' +++ b/file @@ -0,0 +1 @@ EOF - test-tool genzeros $((1024 * 1024 * 1023)) + test-tool genbytes NUL $((1024 * 1024 * 1023)) } | test_must_fail git apply 2>err && test_grep "patch too large" err ' diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 6cecfbeaa1..974bd21f1e 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -522,7 +522,7 @@ corrupt_graph_and_verify() { zero_pos=${4:-${orig_size}} && printf "$data" | dd of="full/$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc && dd of="full/$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null && - test-tool genzeros $(($orig_size - $zero_pos)) >>"full/$objdir/info/commit-graph" && + test-tool genbytes NUL $(($orig_size - $zero_pos)) >>"full/$objdir/info/commit-graph" && corrupt_graph_verify "$grepstr" }
-- gitgitgadget