better error handling
authorJan Pospíšil <honik@ntc.zcu.cz>
Tue, 2 Sep 2008 11:52:21 +0000 (11:52 +0000)
committerJan Pospíšil <honik@ntc.zcu.cz>
Tue, 2 Sep 2008 11:52:21 +0000 (11:52 +0000)
org.glite.testsuites.ctb/LB/lb-common.sh
org.glite.testsuites.ctb/LB/lb-test-logger-remote.sh
org.glite.testsuites.ctb/LB/lb-test-server-remote.sh
org.glite.testsuites.ctb/LB/test-common.sh

index da56a58..5d6172e 100755 (executable)
@@ -52,8 +52,7 @@ DEBUG=2
 function ping_host()
 {
        if [ -z $1 ]; then
-               print_newline
-               print_error "No host to ping"
+               set_error "No host to ping"
                return $TEST_ERROR
        fi
        PING_HOST=$1
@@ -77,16 +76,16 @@ function check_exec()
        fi
        # XXX: maybe use bash's command type?
        which $1 > /dev/null 2>&1
-    if [ $? -eq 0 ]; then
-        local ret=`which $1`
-        if [ -x "$ret" ]; then
-            return $TEST_OK
-        else 
-            return $TEST_ERROR
-        fi
-    else 
-        return $TEST_ERROR
-    fi
+       if [ $? -eq 0 ]; then
+               local ret=`which $1`
+               if [ -x "$ret" ]; then
+                       return $TEST_OK
+               else 
+                       return $TEST_ERROR
+               fi
+       else 
+               return $TEST_ERROR
+       fi
     
 #      if [ $? -eq 0 ] && [ -x "$ret" ]; then 
 #        return $TEST_OK
@@ -103,7 +102,7 @@ function check_binaries()
        do      
                check_exec $file 
                if [ $? -gt 0 ]; then
-                       print_error "file $file not found"
+                       update_error "file $file not found"
                        return $TEST_ERROR
                fi
        done
@@ -114,11 +113,10 @@ function check_binaries()
 function check_socket()
 {
        if [ $# -lt 2 ]; then
-               print_newline
-               print_error "No host:port to check"
+               set_error "No host:port to check"
                return $TEST_ERROR
        fi
-       $TEST_SOCKET $1 $2
+       $TEST_SOCKET $1 $2 2> $testerrfile
        if [ $? -eq 0 ];  then 
                return $TEST_OK
        else
index 39c6383..b4259e5 100755 (executable)
@@ -85,6 +85,7 @@ printf "Testing if all binaries are available"
 check_binaries
 if [ $? -gt 0 ]; then
         test_failed
+       print_error "Some binaries are missing"
 else
         test_done
 fi
@@ -98,7 +99,7 @@ if [ $? -gt 0 ]; then
 else
        test_done
 fi
+
 # check_services
 printf "Testing LB logger at ${LB_HOST}:${GLITE_LB_LOGGER_PORT} (logging)"
 check_socket ${LB_HOST} ${GLITE_LB_LOGGER_PORT}
index a18a3dc..2fabbf0 100755 (executable)
@@ -86,6 +86,7 @@ printf "Testing if all binaries are available"
 check_binaries
 if [ $? -gt 0 ]; then
        test_failed
+       print_error "Some binaries are missing"
 else
        test_done
 fi
index a269bfc..208a597 100644 (file)
@@ -45,6 +45,9 @@ export LINES COLUMNS
 TEST_ERROR=1
 TEST_OK=0
 
+# test error file
+testerrfile=$$.err
+
 function set_test()
 {
 test_done="${spacefill}${begin_green}done${end_green}"
@@ -68,8 +71,8 @@ function test_skipped()       { printf "${test_skipped}${lf}"; }
 function test_dead()   { printf "${test_dead}${lf}"; }
 function test_unused() { printf "${test_unused}${lf}"; }
 function test_unknown  { printf "${test_unknown}${lf}"; }
-function test_start()  { syslog "${test_start}"; }
-function test_end()    { syslog "${test_end}"; }
+function test_start()  { syslog "${test_start}"; reset_error }
+function test_end()    { syslog "${test_end}"; reset_error }
 
 # set output to ASCII (without colors)
 function setOutputASCII()
@@ -162,9 +165,26 @@ end_white="$ENDFONT"
 set_test
 }
 
+function reset_error()
+{
+       rm $testerrfile
+}
+
+function set_error()
+{
+       printf "%s ${lf}" "$*" > $testerrfile
+}
+
+function update_error()
+{
+       printf "%s; " "$*" >> $testerrfile
+}
+
 function print_error()
 {
        printf "${begin_red}Error${end_red}: %s ${lf}" "$*"
+       printf "${begin_red}Error${end_red}: %s ${lf}" "`cat $testerrfile`"
+       reset_error
 }
 
 function print_warning()