]> git.tue.mpg.de Git - paraslash.git/commitdiff
Add t0003-writer-init-error-path.sh.
authorAndre Noll <maan@systemlinux.org>
Sun, 20 Feb 2011 17:15:51 +0000 (18:15 +0100)
committerAndre Noll <maan@systemlinux.org>
Mon, 28 Feb 2011 00:42:32 +0000 (01:42 +0100)
This catches the bugs recently found in the alsa and oss writers.

We need to test that certain commands fail but must distinguish between
failure due to non-zero exit codes and other failures, for example if
a command segfaults. Therefore this patch adds test_expect_failure()
to test-lib.sh which can be called by the individual tests and DTRT.

t/t0003-writer-init-error-path.sh [new file with mode: 0755]
t/test-lib.sh

diff --git a/t/t0003-writer-init-error-path.sh b/t/t0003-writer-init-error-path.sh
new file mode 100755 (executable)
index 0000000..15f1dd8
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+test_description='Check if alsa_init() failures are handled gracefully.
+
+Older parasslash versions contained a bug which caused para_write and para_audiod
+to abort if the alsa/oss device could not be opened. This test makes sure we
+will not introduce the same bug again.'
+
+. ${0%/*}/test-lib.sh
+
+for i in alsa oss; do
+       test_require_objects "${i}_write"
+       missing_objects="$result"
+       if [[ -n "$missing_objects" ]]; then
+               test_skip "$i" "missing object(s): $missing_objects"
+               continue
+       fi
+       test_expect_failure "$i" "
+               head -c 100 /dev/zero | $PARA_WRITE -w '$i -d /dev/non_existent'
+               "
+done
+test_done
index e444e5780d2f152eb9755916375996c9340016cd..b7d675ea0def671529e13732c52143bb22290288 100644 (file)
@@ -61,13 +61,36 @@ say()
        say_color info "$*"
 }
 
+retval_ok()
+{
+       local rv="$1" expectation="$2"
+
+       if [[ "$expectation" == "success" ]]; then
+               (($rv == 0)) && return 0 || return 1
+       fi
+       if (($rv > 129 && $rv <= 192)); then
+               echo >&2 "died by signal"
+               return 1
+       fi
+       if (($rv == 127)); then
+                echo >&2 "command not found"
+               return 1
+       fi
+       if (($rv == 0)); then
+                echo >&2 "command was supposed to fail but succeeded"
+               return 1
+       fi
+       return 0
+}
+
 _test_run()
 {
-       local f
+       local f expectation="$3" ret
 
        let test_count++
        eval >&3 2>&4 "$2"
-       if (($? == 0)); then
+       ret=$?
+       if retval_ok "$ret" "$expectation"; then
                let test_success++
                say_color ok "ok $test_count - $1"
                return
@@ -140,7 +163,15 @@ test_expect_success()
 {
        (($# != 2)) && error "bug: not 2 parameters to test_expect_success()"
        say >&3 "expecting success: $2"
-       _test_run "$1" "$2"
+       _test_run "$1" "$2" "success"
+       echo >&3 ""
+}
+
+test_expect_failure()
+{
+       (($# != 2)) && error "bug: not 2 parameters to test_expect_failure()"
+       say >&3 "expecting failure: $2"
+       _test_run "$1" "$2" "failure"
        echo >&3 ""
 }