Mercurial > hg > audiodb
annotate tests/test-utils.sh @ 87:e64a2e7f543c
Initial web services startup / shutdown test.
The test framework could definitely do with work here; the server
process must run in the background, so there are race conditions both on
startup and shutdown. The current workaround is "sleep 1", which is
both inelegant and slow.
author | mas01cr |
---|---|
date | Tue, 02 Oct 2007 15:28:11 +0000 |
parents | f258a0258755 |
children | 03564e8988a2 |
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 } |
mas01cr@87 | 50 |
mas01cr@87 | 51 # Web services utilities |
mas01cr@87 | 52 start_server() { |
mas01cr@87 | 53 $1 -s $2 & |
mas01cr@87 | 54 # HACK: deal with race on process creation |
mas01cr@87 | 55 sleep 1 |
mas01cr@87 | 56 } |
mas01cr@87 | 57 |
mas01cr@87 | 58 stop_server() { |
mas01cr@87 | 59 grep ${AUDIODB} /proc/$1/cmdline > /dev/null |
mas01cr@87 | 60 kill $1 |
mas01cr@87 | 61 # HACK: deal with race on process exit |
mas01cr@87 | 62 sleep 1 |
mas01cr@87 | 63 expect_clean_error_exit grep ${AUDIODB} /proc/$1/cmdline |
mas01cr@87 | 64 } |
mas01cr@87 | 65 |
mas01cr@87 | 66 check_server() { |
mas01cr@87 | 67 grep ${AUDIODB} /proc/$1/cmdline > /dev/null |
mas01cr@87 | 68 } |