# Common definitions for all test suites. # Copyright 2012 Serval Project Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. shopt -s extglob testdefs_sh=$(abspath "${BASH_SOURCE[0]}") servald_source_root="${testdefs_sh%/*}" servald_build_root="$servald_source_root" servald_basename="servald" servald_build_executable="$servald_build_root/$servald_basename" export TFW_LOGDIR="${TFW_LOGDIR:-$servald_build_root/testlog}" addr_localhost="127.0.0.1" declare -a instance_stack=() # Some useful string constants. LF=' ' CR=' ' HT=' ' # Some useful regular expressions. These must work in grep(1) as basic # expressions, and also in sed(1). rexp_sid='[0-9a-fA-F]\{64\}' rexp_did='[0-9+#]\{5,\}' # Utility function for extracting information from the output of servald # commands that return "key:value\n" pairs. # # extract_stdout_keyvalue_optional [] # # Examines the standard output of the last command executed using "execute" or # any of its variants. If there is a line matching # "\n" then assigns the part matched by # into the shell variable called and returns 0. # Otherwise, leaves unchanged and returns 1. # # The default is ':'. # extract_stdout_keyvalue_optional() { local _var="$1" local _label="$2" local _delim=':' local _rexp="$3" case $# in 3) ;; 4) _delim="$3"; _rexp="$4";; *) error "invalid number of args";; esac local _label_re=$(escape_grep_basic "$_label") local _delim_re=$(escape_grep_basic "$_delim") local _line=$($GREP "^$_label_re$_delim_re" "$TFWSTDOUT") local _value= local _return=1 if [ -n "$_line" ]; then _value="${_line#*$_delim}" _return=0 if [ -n "$_var" ]; then eval $_var="\$_value" eval tfw_log "$_var=\$(shellarg "\${$_var}")" fi fi return $_return } # Utility function for extracting information from the output of servald # commands that return "key:value\n" pairs. extract_stdout_keyvalue() { local _label="$2" assert --message="stdout of ($executed) contains valid '$_label:' line" --stdout extract_stdout_keyvalue_optional "$@" } # Parse the standard result set output produced by the immediately preceding command # command into the following shell variables: # NCOLS the number of columns # NROWS the number of data rows (not counting headers) # HEADER[c] the C-th header label, 0 <= C <= NCOLS-1 #