annotate tests/test-utils.sh @ 409:99e6cbad7f76 api-inversion

The lesser of two evils, part 2. Implement paths through audiodb_insert_datum_internal() for databases with O2_FLAG_LARGE_ADB, including in some of the helper functions. Most of the nasty stuff is concentrated in writing out the paths in what is now step 6, and everything else looks much as before, apart from a renumbering of the steps taken. Now we can implement audiodb_insert() for O2_FLAG_LARGE_ADB databases; we need to construct an adb_datum_internal_t from our adb_insert_t, but that's straightforward -- even just about straightforward enough to do it inline. Then audioDB::batchinsert() can be rewritten completely in terms of API functions, and doesn't need any kind of special treatment for the large case. Hooray. The real point of that is of course that we can now delete wodges of dead code, and move out audioDB::insert and audioDB::batchinsert into audioDB.cpp, because all they're doing now is dealing with command-line logic. This point marks the limit of what can be achieved in terms of "API inversion" at this time; the only remaining function, audiodb_query() / audioDB::query cannot be inverted because its API implementation is incomplete. Future plans, in some order: - merge this branch to trunk (check with current API/ABI clients); - complete audiodb_query() implementation; - invert audioDB::query / audiodb_query(); - MORE TESTS; - remove audioDB.cpp from list of files compiled into the library; - implement missing API functions (index, liszt, sample) directly; - source code rearrangement into library and command-line directories; - include bindings to library for some plausible candidate environments (Perl, Python, Lisp, Pd, Max/MSP) as examples; - API documentation.
author mas01cr
date Tue, 09 Dec 2008 22:48:30 +0000
parents e21cc48ddf4d
children d5ada9532a40
rev   line source
mas01cr@48 1 # no shebang line: this file should be sourced by run-test.sh files
mas01cr@48 2
mas01cr@101 3 set -E
mas01cr@101 4
mas01cr@48 5 trap "exit 1" ERR
mas01cr@48 6
mas01cr@198 7 if [ -z "${AUDIODB}" ]; then
mas01cr@48 8 AUDIODB=../../audioDB
mas01cr@48 9 fi
mas01cr@48 10
mas01cr@48 11 # FIXME: maybe generalize to multiple arguments? Also, implement it
mas01cr@48 12 # properly, rather than just for a few floats that we know how to
mas01cr@48 13 # encode. This might involve writing some C code, as Bash doesn't do
mas01cr@48 14 # Floating Point. (scanf() is probably enough).
mas01cr@48 15
mas01cr@54 16 expect_clean_error_exit() {
mas01cr@54 17 trap - ERR
mas01cr@54 18 "$@"
mas01cr@54 19 exit_code=$?
mas01cr@54 20 trap "exit 1" ERR
mas01cr@54 21 if [ $exit_code -eq 0 ]; then
mas01cr@54 22 exit 1
mas01cr@54 23 elif [ $exit_code -ge 126 ]; then
mas01cr@54 24 exit 1
mas01cr@54 25 fi
mas01cr@54 26 }
mas01cr@54 27
mas01cr@48 28 floatstring() {
mas01cr@48 29 for arg in "$@"; do
mas01cr@48 30 case ${arg} in
mas01cr@48 31 0)
mas01cr@48 32 printf "\x00\x00\x00\x00\x00\x00\x00\x00";;
mas01cr@193 33 -0.5)
mas01cr@193 34 printf "\x00\x00\x00\x00\x00\x00\xe0\xbf";;
mas01cr@48 35 0.5)
mas01cr@48 36 printf "\x00\x00\x00\x00\x00\x00\xe0\x3f";;
mas01cr@193 37 -1)
mas01cr@193 38 printf "\x00\x00\x00\x00\x00\x00\xf0\xbf";;
mas01cr@48 39 1)
mas01cr@48 40 printf "\x00\x00\x00\x00\x00\x00\xf0\x3f";;
mas01cr@48 41 *)
mas01cr@48 42 echo "bad arg to floatstring(): ${arg}"
mas01cr@48 43 exit 1;;
mas01cr@48 44 esac
mas01cr@48 45 done
mas01cr@48 46 }
mas01cr@48 47
mas01cr@48 48 # FIXME: likewise. And endianness issues (which are a reflection of
mas01cr@48 49 # the endianness of audioDB as of 2007-09-18, unfortunately).
mas01cr@48 50
mas01cr@48 51 intstring() {
mas01cr@48 52 # works up to 9 for now
mas01cr@48 53 if [ $1 -ge 10 ]; then echo "intstring() arg too large: ${1}"; exit 1; fi
mas01cr@48 54 printf "%b\x00\x00\x00" "\\x${1}"
mas01cr@48 55 }
mas01cr@87 56
mas01cr@87 57 # Web services utilities
mas01cr@87 58 start_server() {
mas01cr@87 59 $1 -s $2 &
mas01cr@87 60 # HACK: deal with race on process creation
mas01cr@87 61 sleep 1
mas01cr@101 62 trap 'kill $!; exit 1' ERR
mas01cr@87 63 }
mas01cr@87 64
mas01cr@87 65 stop_server() {
mas01cr@198 66 grep "${AUDIODB}" /proc/$1/cmdline > /dev/null
mas01cr@87 67 kill $1
mas01cr@87 68 # HACK: deal with race on process exit
mas01cr@87 69 sleep 1
mas01cr@87 70 expect_clean_error_exit grep ${AUDIODB} /proc/$1/cmdline
mas01cr@87 71 }
mas01cr@87 72
mas01cr@87 73 check_server() {
mas01cr@198 74 grep "${AUDIODB}" /proc/$1/cmdline > /dev/null
mas01cr@87 75 }
mas01cr@94 76
mas01cr@95 77 expect_client_failure() {
mas01cr@94 78 # FIXME: work out whether and how the client should report server
mas01cr@94 79 # errors. At present, the client exits with a zero exit code.
mas01cr@94 80 "$@"
mas01cr@94 81 }