diff --git a/debian/tests/symbols b/debian/tests/symbols index e84270dc8db477a7d5ebeb8cb9c274ee7688da32..7ea4e9796868d41b27084d29049c7c105d8ad143 100755 --- a/debian/tests/symbols +++ b/debian/tests/symbols @@ -26,7 +26,7 @@ if ! bwrap --ro-bind / / true; then fi scratch="$(mktemp -d)" -echo "# Working directory: $scratch" +echo_tap "# Working directory: $scratch" cd "$scratch" trap 'cd /; rm -fr $scratch' EXIT host="${scratch}/host" @@ -38,6 +38,7 @@ CAPSULE_SYMBOLS="$(pkg-config --variable=libexecdir capsule)/capsule-symbols" # libcapsule itself :-) bwrap --ro-bind / / --ro-bind / "${host}" --dev-bind /dev /dev \ ${CAPSULE_SYMBOLS} libcapsule.so.0 "${host}" > output +capture_tap sed -e 's/^/# /' < output pass "Ran ${CAPSULE_SYMBOLS} libcapsule.so.0 ${host}" shell_is 'grep "^capsule_init" output' 0 "capsule_init " \ @@ -47,6 +48,7 @@ shell_is 'grep -v "^capsule" output' 1 "" \ # Try the same thing without a prefix ${CAPSULE_SYMBOLS} libcapsule.so.0 / > output +capture_tap sed -e 's/^/# /' < output pass "Ran ${CAPSULE_SYMBOLS} libcapsule.so.0 /" shell_is 'grep "^capsule_init" output' 0 "capsule_init " \ @@ -56,6 +58,7 @@ shell_is 'grep -v "^capsule" output' 1 "" \ # How about versioned symbols? ${CAPSULE_SYMBOLS} libjpeg.so.62 / > output +capture_tap sed -e 's/^/# /' < output pass "Ran ${CAPSULE_SYMBOLS} libjpeg.so.62 /" shell_is 'grep "^jpeg_destroy " output' 0 'jpeg_destroy @@LIBJPEG_6.2' \ diff --git a/debian/tests/version b/debian/tests/version index 892e5b5c58fc436d6fe6a6dccd2fa758896a4cff..4c6f97de2e21dbb358273ea1989be36b987b3dcb 100755 --- a/debian/tests/version +++ b/debian/tests/version @@ -26,7 +26,7 @@ if ! bwrap --ro-bind / / true; then fi scratch="$(mktemp -d)" -echo "# Working directory: $scratch" +echo_tap "# Working directory: $scratch" cd "$scratch" trap 'cd /; rm -fr $scratch' EXIT host="${scratch}/host" diff --git a/tests/libtest.sh b/tests/libtest.sh index b96d9a266e493410324272f7062681260315a365..4ffe6bedea8a57d30ccbd1485937110ce880d697 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Lesser General Public # License along with libcapsule. If not, see <http://www.gnu.org/licenses/>. +exec {test_tap_fd}>&1 +exec >&2 test_tempdir="$(mktemp -d /tmp/libcapsule.XXXXXXXX)" trap 'rm -fr --one-file-system $test_tempdir' EXIT mkdir "$test_tempdir/host" @@ -25,25 +27,33 @@ export CAPSULE_PREFIX="$test_tempdir/host" test_num=0 any_failed=0 +capture_tap () { + "$@" >&${test_tap_fd} +} + +echo_tap () { + echo "$*" >&${test_tap_fd} +} + skip_all () { - echo "1..0 # SKIP - $*" + echo_tap "1..0 # SKIP - $*" exit 0 } pass () { test_num=$((test_num + 1)) - echo "ok $test_num - $*" + echo_tap "ok $test_num - $*" } fail () { test_num=$((test_num + 1)) - echo "not ok $test_num - $*" + echo_tap "not ok $test_num - $*" any_failed=1 } skip () { test_num=$((test_num + 1)) - echo "ok $test_num # SKIP - $*" + echo_tap "ok $test_num # SKIP - $*" } ok () { @@ -65,8 +75,8 @@ is () { if [ "x$got" = "x$expected" ]; then pass "$* ($got)" else - echo "# Got: $got" - echo "# Expected: $expected" + echo_tap "# Got: $got" + echo_tap "# Expected: $expected" fail "$* ($got != $expected)" fi } @@ -79,8 +89,8 @@ like () { if [[ $got == $expected ]]; then pass "$* ($got matches $expected)" else - echo "# Got: $got" - echo "# Expected extglob: $expected" + echo_tap "# Got: $got" + echo_tap "# Expected extglob: $expected" fail "$* ($got does not match $expected)" fi } @@ -91,8 +101,8 @@ isnt () { shift 2 if [ "x$got" != "x$unexpected" ]; then - echo "# Got: $got" - echo "# Expected: anything but $unexpected" + echo_tap "# Got: $got" + echo_tap "# Expected: anything but $unexpected" fail "$* (expected anything but $unexpected)" else pass "$* ($got)" @@ -115,19 +125,19 @@ shell_is () { if [ "x$got" = "x$expected" ]; then pass "$* ($got)" else - echo "# Got: $got" - echo "# Expected: $expected" + echo_tap "# Got: $got" + echo_tap "# Expected: $expected" fail "$* ($got != $expected)" fi } run_verbose () { - echo "# \$($*)..." + echo_tap "# \$($*)..." "$@" } done_testing () { - echo "# End of tests" - echo "1..$test_num" + echo_tap "# End of tests" + echo_tap "1..$test_num" exit $any_failed } diff --git a/tests/notgl.sh b/tests/notgl.sh index c2adf5bc09645cb8312a49f8337001576b9536f1..beded1c6d41f0cfcb352cc207596c2788c11e524 100755 --- a/tests/notgl.sh +++ b/tests/notgl.sh @@ -28,27 +28,27 @@ fi : ${G_TEST_SRCDIR:="$(cd "$(dirname "$0")"/..; pwd)"} : ${G_TEST_BUILDDIR:="$(cd "$(dirname "$0")"/..; pwd)"} -echo "# Source or installation directory: $G_TEST_SRCDIR" -echo "# Build or installation directory: $G_TEST_BUILDDIR" +echo_tap "# Source or installation directory: $G_TEST_SRCDIR" +echo_tap "# Build or installation directory: $G_TEST_BUILDDIR" if [ -n "${CAPSULE_TESTS_UNINSTALLED:-}" ]; then - echo "# Running uninstalled: yes" + echo_tap "# Running uninstalled: yes" # We need to bypass libtool because it plays around with # LD_LIBRARY_PATH, and so do we. libs=/.libs notgl_user="$("$G_TEST_BUILDDIR/libtool" --mode=execute ls -1 "$G_TEST_BUILDDIR/tests/notgl-user")" notgl_helper_user="$("$G_TEST_BUILDDIR/libtool" --mode=execute ls -1 "$G_TEST_BUILDDIR/tests/notgl-helper-user")" else - echo "# Running uninstalled: no" + echo_tap "# Running uninstalled: no" libs= notgl_user="$G_TEST_BUILDDIR/tests/notgl-user" notgl_helper_user="$G_TEST_BUILDDIR/tests/notgl-helper-user" fi -echo -echo "# Without special measures:" +echo_tap +echo_tap "# Without special measures:" run_verbose env LD_LIBRARY_PATH="$G_TEST_BUILDDIR/tests/lib$libs" "$notgl_user" > "$test_tempdir/output" -sed -e 's/^/# /' "$test_tempdir/output" +capture_tap sed -e 's/^/# /' "$test_tempdir/output" shell_is \ 'sed -ne "s/^NotGL implementation: //p" $test_tempdir/output' \ 0 reference @@ -65,9 +65,9 @@ shell_is \ 'sed -ne "s/^notgl_extension_green: //p" $test_tempdir/output' \ 0 "(not found)" -echo +echo_tap run_verbose env LD_LIBRARY_PATH="$G_TEST_BUILDDIR/tests/lib$libs" "$notgl_helper_user" > "$test_tempdir/output" -sed -e 's/^/# /' "$test_tempdir/output" +capture_tap sed -e 's/^/# /' "$test_tempdir/output" shell_is \ 'sed -ne "s/^NotGL implementation: //p" $test_tempdir/output' \ 0 reference @@ -84,8 +84,8 @@ shell_is \ 'sed -ne "s/^NotGL helper implementation as seen by executable: //p" $test_tempdir/output' \ 0 "container (reference)" -echo -echo "# With libcapsule:" +echo_tap +echo_tap "# With libcapsule:" # We mount the "host system" on $test_tempdir/host. # # In the "container", the shim libnotgl is picked up from tests/shim because @@ -103,7 +103,7 @@ run_verbose bwrap \ --ro-bind "$G_TEST_BUILDDIR/tests/red" "$CAPSULE_PREFIX$G_TEST_BUILDDIR/tests/lib" \ --setenv LD_LIBRARY_PATH "$G_TEST_BUILDDIR/tests/shim$libs:$G_TEST_BUILDDIR/tests/lib$libs" \ "$notgl_user" > "$test_tempdir/output" -sed -e 's/^/# /' "$test_tempdir/output" +capture_tap sed -e 's/^/# /' "$test_tempdir/output" # Functions from libnotgl get dispatched through the shim to the "red" # implementation from the "host system". This mirrors functions from libGL # being dispatched through the shim to the AMD implementation of libGL. @@ -130,7 +130,7 @@ shell_is \ 'sed -ne "s/^notgl_extension_green: //p" $test_tempdir/output' \ 0 "(not found)" -echo +echo_tap # Similar to the above, but now the host system is using the "green" # implementation of libnotgl, mirroring the NVIDIA implementation of libGL. run_verbose bwrap \ @@ -141,7 +141,7 @@ run_verbose bwrap \ --ro-bind "$G_TEST_BUILDDIR/tests/green" "$CAPSULE_PREFIX$G_TEST_BUILDDIR/tests/lib" \ --setenv LD_LIBRARY_PATH "$G_TEST_BUILDDIR/tests/shim$libs:$G_TEST_BUILDDIR/tests/lib$libs" \ "$notgl_helper_user" > "$test_tempdir/output" -sed -e 's/^/# /' "$test_tempdir/output" +capture_tap sed -e 's/^/# /' "$test_tempdir/output" shell_is \ 'sed -ne "s/^NotGL implementation: //p" $test_tempdir/output' \ 0 green