Mercurial > hg > audiodb
annotate tests/test-utils.sh @ 54:f258a0258755
Just testing for failure exit codes doesn't distinguish between a clean
error exit and a segfault. Define a shell function for clean error
exit, and use it everywhere.
author | mas01cr |
---|---|
date | Thu, 20 Sep 2007 09:52:16 +0000 |
parents | a7aad4c50cb9 |
children | e64a2e7f543c |
rev | line source |
---|---|
mas01cr@48 | 1 # no shebang line: this file should be sourced by run-test.sh files |
mas01cr@48 | 2 |
mas01cr@48 | 3 trap "exit 1" ERR |
mas01cr@48 | 4 |
mas01cr@48 | 5 if [ -z ${AUDIODB} ]; then |
mas01cr@48 | 6 AUDIODB=../../audioDB |
mas01cr@48 | 7 fi |
mas01cr@48 | 8 |
mas01cr@48 | 9 # FIXME: maybe generalize to multiple arguments? Also, implement it |
mas01cr@48 | 10 # properly, rather than just for a few floats that we know how to |
mas01cr@48 | 11 # encode. This might involve writing some C code, as Bash doesn't do |
mas01cr@48 | 12 # Floating Point. (scanf() is probably enough). |
mas01cr@48 | 13 |
mas01cr@54 | 14 expect_clean_error_exit() { |
mas01cr@54 | 15 trap - ERR |
mas01cr@54 | 16 "$@" |
mas01cr@54 | 17 exit_code=$? |
mas01cr@54 | 18 trap "exit 1" ERR |
mas01cr@54 | 19 if [ $exit_code -eq 0 ]; then |
mas01cr@54 | 20 exit 1 |
mas01cr@54 | 21 elif [ $exit_code -ge 126 ]; then |
mas01cr@54 | 22 exit 1 |
mas01cr@54 | 23 fi |
mas01cr@54 | 24 } |
mas01cr@54 | 25 |
mas01cr@48 | 26 floatstring() { |
mas01cr@48 | 27 for arg in "$@"; do |
mas01cr@48 | 28 case ${arg} in |
mas01cr@48 | 29 0) |
mas01cr@48 | 30 printf "\x00\x00\x00\x00\x00\x00\x00\x00";; |
mas01cr@48 | 31 0.5) |
mas01cr@48 | 32 printf "\x00\x00\x00\x00\x00\x00\xe0\x3f";; |
mas01cr@48 | 33 1) |
mas01cr@48 | 34 printf "\x00\x00\x00\x00\x00\x00\xf0\x3f";; |
mas01cr@48 | 35 *) |
mas01cr@48 | 36 echo "bad arg to floatstring(): ${arg}" |
mas01cr@48 | 37 exit 1;; |
mas01cr@48 | 38 esac |
mas01cr@48 | 39 done |
mas01cr@48 | 40 } |
mas01cr@48 | 41 |
mas01cr@48 | 42 # FIXME: likewise. And endianness issues (which are a reflection of |
mas01cr@48 | 43 # the endianness of audioDB as of 2007-09-18, unfortunately). |
mas01cr@48 | 44 |
mas01cr@48 | 45 intstring() { |
mas01cr@48 | 46 # works up to 9 for now |
mas01cr@48 | 47 if [ $1 -ge 10 ]; then echo "intstring() arg too large: ${1}"; exit 1; fi |
mas01cr@48 | 48 printf "%b\x00\x00\x00" "\\x${1}" |
mas01cr@48 | 49 } |