Merge branch 'rb/no-dev-zero-in-test'
authorJunio C Hamano <gitster@pobox.com>
Thu, 14 Feb 2019 02:18:43 +0000 (18:18 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Feb 2019 02:18:43 +0000 (18:18 -0800)
* rb/no-dev-zero-in-test:
t5562: replace /dev/zero with a pipe from generate_zero_bytes
t5318: replace use of /dev/zero with generate_zero_bytes
test-lib-functions.sh: add generate_zero_bytes function

t/t5318-commit-graph.sh
t/t5562-http-backend-content-length.sh
t/test-lib-functions.sh
index 16d10ebce82fa1fc2e4396f8d30911541b96d7b6..d4bd1522fe2e6e94578b2d6f709005c7a271b4b0 100755 (executable)
@@ -383,7 +383,7 @@ corrupt_graph_and_verify() {
        cp $objdir/info/commit-graph commit-graph-backup &&
        printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
        dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" count=0 &&
-       dd if=/dev/zero of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" count=$(($orig_size - $zero_pos)) &&
+       generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
        test_must_fail git commit-graph verify 2>test_err &&
        grep -v "^+" test_err >err &&
        test_i18ngrep "$grepstr" err
index 90d890d02fd8f5451d0d78d880f6698d11b22a3d..bbadde2c6e6df58aebcc7e378824993cdefb31fd 100755 (executable)
@@ -143,14 +143,14 @@ test_expect_success GZIP 'push gzipped empty' '
 
 test_expect_success 'CONTENT_LENGTH overflow ssite_t' '
        NOT_FIT_IN_SSIZE=$(ssize_b100dots) &&
-       env \
+       generate_zero_bytes infinity  | env \
                CONTENT_TYPE=application/x-git-upload-pack-request \
                QUERY_STRING=/repo.git/git-upload-pack \
                PATH_TRANSLATED="$PWD"/.git/git-upload-pack \
                GIT_HTTP_EXPORT_ALL=TRUE \
                REQUEST_METHOD=POST \
                CONTENT_LENGTH="$NOT_FIT_IN_SSIZE" \
-               git http-backend </dev/zero >/dev/null 2>err &&
+               git http-backend >/dev/null 2>err &&
        grep "fatal:.*CONTENT_LENGTH" err
 '
 
index 969e2ba6dadd50ecb3a5a03fe9f8c72527eac279..094c07748aad423bff0eb8d5ff65ddceb3a4f5a6 100644 (file)
@@ -116,6 +116,19 @@ remove_cr () {
        tr '\015' Q | sed -e 's/Q$//'
 }
 
+# Generate an output of $1 bytes of all zeroes (NULs, not ASCII zeroes).
+# If $1 is 'infinity', output forever or until the receiving pipe stops reading,
+# whichever comes first.
+generate_zero_bytes () {
+       perl -e 'if ($ARGV[0] == "infinity") {
+               while (-1) {
+                       print "\0"
+               }
+       } else {
+               print "\0" x $ARGV[0]
+       }' "$@"
+}
+
 # In some bourne shell implementations, the "unset" builtin returns
 # nonzero status when a variable to be unset was not set in the first
 # place.