X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=t%2Ftest-lib-functions.sh;h=80402a428f7735a031658a904d4f623f38e43464;hb=f80fcd36751c85b11722f8c7cfd537c28956400e;hp=6b3bbf99e46cf7cc418eca1eaf768d526ac658aa;hpb=a9f2d3f200d9d8b6e803c0818b1163226bbc3994;p=platform%2Fupstream%2Fgit.git diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 6b3bbf9..80402a4 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -116,6 +116,13 @@ 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 () { + test-tool genzeros "$@" +} + # In some bourne shell implementations, the "unset" builtin returns # nonzero status when a variable to be unset was not set in the first # place. @@ -1263,3 +1270,42 @@ test_oid () { fi && eval "printf '%s' \"\${$var}\"" } + +# Choose a port number based on the test script's number and store it in +# the given variable name, unless that variable already contains a number. +test_set_port () { + local var=$1 port + + if test $# -ne 1 || test -z "$var" + then + BUG "test_set_port requires a variable name" + fi + + eval port=\$$var + case "$port" in + "") + # No port is set in the given env var, use the test + # number as port number instead. + # Remove not only the leading 't', but all leading zeros + # as well, so the arithmetic below won't (mis)interpret + # a test number like '0123' as an octal value. + port=${this_test#${this_test%%[1-9]*}} + if test "${port:-0}" -lt 1024 + then + # root-only port, use a larger one instead. + port=$(($port + 10000)) + fi + ;; + *[!0-9]*|0*) + error >&7 "invalid port number: $port" + ;; + *) + # The user has specified the port. + ;; + esac + + # Make sure that parallel '--stress' test jobs get different + # ports. + port=$(($port + ${GIT_TEST_STRESS_JOB_NR:-0})) + eval $var=$port +}