Rework test scripts
[SXSI/xpathcomp.git] / tests / non_regression_tests / qizx.sh
index d9f56dd..2226239 100755 (executable)
 #!/bin/bash
-QIZX="/usr/local/bin/alarm 600 22000000 /raid0/kn/qizx/qizx-fe-4.1p1/bin/qizx"
+QIZX="/raid0/kn/qizx/qizx-fe-4.1p1/bin/qizx.alarm"
+
+source utils.sh
+
+function stop_qizx() {
+    sleep 2
+    rm -rf mat.xq count.xq
+    QIZXPIDS=`ps xwww --format "%p,%a" | grep java | grep qizx | cut -f 1 -d ' '`
+    for i in $QIZXPIDS
+    do
+       kill -TERM "$i"
+       sleep 2
+       KILLED=`ps aux | grep '^'$i`
+       if [ "$KILLED" ]
+       then
+           kill -9 "$i"
+       fi
+       sleep 3
+       rm -f /raid0/kn/qizxlib/*/lock
+       while true
+       do
+           o=/raid0/kn/qizx/qizx-fe-4.1p1/bin/qizx -g /raid0/kn/qizxlib/ -l xmark -check /tmp/log >/dev/null 2>&1
+           sleep 2
+           if [ -z "$o" ]
+           then
+               break
+           fi
+       done
+    done
+
+}
+
+trap stop_qizx INT TERM
 
 function do_qizx() {
-    
+
+    stop_qizx
+
     query="$1"
-    doc=`basename "$2" .xml`
+    doc=`basename "$2"`
+    repeat="$3"
     echo 'let $doc := collection("'"$doc"'") return count($doc'"$query"')' > count.xq
     echo 'let $doc := collection("'"$doc"'") return $doc'"$query" > mat.xq
-    {
-       read count;
-    } < <($QIZX -g /raid0/kn/qizxlib/ -l xmark count.xq 2>&1 )
-    {
-       read time_count;
-    } < <($QIZX -g /raid0/kn/qizxlib/ -l xmark -mr 4 count.xq 2>&1 | grep evaluation | cut -f2 -d ',' | grep -o '[0-9.]*' | head -1 )    
-
-    {
-       read time_mat;
-    } <  <($QIZX -g /raid0/kn/qizxlib/ -l xmark -mr 2 mat.xq 2>&1 | grep evaluation | cut -f2 -d ',' | grep -o '[0-9.]*' | sort -g | head -1 )    
-    
+
+    IT=0
+    while true
+    do
+       OUTPUT=`$QIZX -g /raid0/kn/qizxlib/ -l xmark count.xq 2>&1`
+       if  echo "$OUTPUT" | grep -q 'java' >/dev/null 2>&1
+       then
+           if [ "$IT" = 5 ]
+           then
+               break
+           fi
+           IT=$(($IT + 1))
+           continue
+       fi
+
+       {
+           read count;
+       } < <(echo "$OUTPUT")
+
+       stop_qizx
+       sleep 3
+       tmp=`echo "$count" | grep -o '[0-9.]\+'`
+       if [ "$tmp" = "$count" ]
+       then
+           break
+       fi
+    done
+
+    IT=0
+    while true
+    do
+
+       OUTPUT=`$QIZX -g /raid0/kn/qizxlib/ -l xmark -r "$repeat" count.xq 2>&1`
+       if  echo "$OUTPUT" | grep -q 'java' >/dev/null 2>&1
+       then
+           if [ "$IT" = 5 ]
+           then
+               break
+           fi
+           IT=$(($IT + 1))
+           continue
+       fi
+
+       {
+           read time_count;
+       } < <(echo "$OUTPUT" | grep 'display time' | cut -f 3 -d : | grep -o '[0-9]\+'| tail -n +1 | average )
+
+
+       stop_qizx
+       sleep 3
+       if [ -z "$time_count" ]
+       then
+           break
+       fi
+       tmp=`echo "$time_count" | grep -o '[0-9.]\+'`
+       if [ "$tmp" = "$time_count" ]
+       then
+           break
+       fi
+    done
+
+    IT=0
+    while true
+    do
+       OUTPUT=`$QIZX -g /raid0/kn/qizxlib/ -l xmark -r "$repeat" mat.xq -out /dev/null 2>&1`
+       if  echo "$OUTPUT" | grep -q 'java' >/dev/null 2>&1
+       then
+           if [ "$IT" = 5 ]
+           then
+               break
+           fi
+           IT=$(($IT + 1))
+           continue
+       fi
+
+       {
+           read time_mat;
+       } <  <(echo "$OUTPUT" 2>&1 | grep 'display time' | cut -f 3 -d : | grep -o '[0-9]\+'| tail -n +1 | average)
+
+       stop_qizx
+       sleep 3
+       if [ -z "$time_mat" ]
+       then
+           break
+       fi
+
+
+       tmp=`echo "$time_mat" | grep -o '[0-9.]\+'`
+       if [ "$tmp" = "$time_mat" ]
+       then
+           break
+       fi
+    done
+
     echo $time_count
     echo 0
-    echo $time_mat 
+    echo $time_mat
     echo $count
 
 }