Rename directory non_regression_tests to comparison_tests
[SXSI/xpathcomp.git] / tests / comparison_tests / qizx.sh
1 #!/bin/bash
2 QIZX="/raid0/kn/qizx/qizx-fe-4.1p1/bin/qizx.alarm"
3
4 source utils.sh
5
6 function stop_qizx() {
7     sleep 2
8 #    rm -rf mat.xq count.xq
9     QIZXPIDS=`ps xwww --format "%p,%a" | grep java | grep qizx | cut -f 1 -d ' '`
10     for i in $QIZXPIDS
11     do
12         kill -TERM "$i"
13         sleep 2
14         KILLED=`ps aux | grep '^'$i`
15         if [ "$KILLED" ]
16         then
17             kill -9 "$i"
18         fi
19         sleep 3
20         rm -f /raid0/kn/qizxlib/*/lock
21         while true
22         do
23             o=/raid0/kn/qizx/qizx-fe-4.1p1/bin/qizx -g /raid0/kn/qizxlib/ -l xmark -check /tmp/log >/dev/null 2>&1
24             sleep 2
25             if [ -z "$o" ]
26             then
27                 break
28             fi
29         done
30     done
31
32 }
33
34 trap stop_qizx INT TERM
35
36 function do_qizx() {
37
38     stop_qizx
39
40     query="$1"
41     doc=`basename "$2"`
42     repeat="$3"
43     count="$4"
44     echo 'let $doc := collection("'"$doc"'") return count($doc'"$query"')' > count.xq
45     echo 'let $doc := collection("'"$doc"'") return $doc'"$query" > mat.xq
46
47     IT=0
48     while true
49     do
50         OUTPUT=`$QIZX -g /raid0/kn/qizxlib/ -l xmark count.xq 2>&1`
51         if  echo "$OUTPUT" | grep -q 'java' >/dev/null 2>&1
52         then
53             if [ "$IT" = 5 ]
54             then
55                 break
56             fi
57             IT=$(($IT + 1))
58             continue
59         fi
60
61         {
62             read count;
63         } < <(echo "$OUTPUT")
64
65         stop_qizx
66         sleep 3
67         tmp=`echo "$count" | grep -o '[0-9.]\+'`
68         if [ "$tmp" = "$count" ]
69         then
70             break
71         fi
72     done
73
74     IT=0
75     while true
76     do
77
78         OUTPUT=`$QIZX -g /raid0/kn/qizxlib/ -l xmark -r "$repeat" count.xq 2>&1`
79         if  echo "$OUTPUT" | grep -q 'java' >/dev/null 2>&1
80         then
81             if [ "$IT" = 5 ]
82             then
83                 break
84             fi
85             IT=$(($IT + 1))
86             continue
87         fi
88
89         {
90             read time_count;
91         } < <(echo "$OUTPUT" | grep 'display time' | cut -f 3 -d : | grep -o '[0-9]\+'| tail -n +1 | average )
92
93
94         stop_qizx
95         sleep 3
96         if [ -z "$time_count" ]
97         then
98             break
99         fi
100         tmp=`echo "$time_count" | grep -o '[0-9.]\+'`
101         if [ "$tmp" = "$time_count" ]
102         then
103             break
104         fi
105         done
106
107     IT=0
108     if [ -z "$count" ]
109     then
110
111         while true
112         do
113             OUTPUT=`$QIZX -g /raid0/kn/qizxlib/ -l xmark -r "$repeat" mat.xq -out /dev/null 2>&1`
114         if  echo "$OUTPUT" | grep -q 'java' >/dev/null 2>&1
115         then
116             if [ "$IT" = 5 ]
117             then
118                 break
119             fi
120             IT=$(($IT + 1))
121             continue
122         fi
123
124         {
125             read time_mat;
126         } <  <(echo "$OUTPUT" 2>&1 | grep 'display time' | cut -f 3 -d : | grep -o '[0-9]\+'| tail -n +1 | average)
127
128         stop_qizx
129         sleep 3
130         if [ -z "$time_mat" ]
131         then
132             break
133         fi
134
135
136         tmp=`echo "$time_mat" | grep -o '[0-9.]\+'`
137         if [ "$tmp" = "$time_mat" ]
138         then
139             break
140         fi
141     done
142     else
143         time_mat="999999"
144     fi
145
146     echo $time_count
147     echo 0
148     echo $time_mat
149     echo $count
150
151 }
152
153 #UGLY HACK TO TRICK QIZX EVALUATION VERSION
154 # OLD_DATE=`date +"%m/%d/%Y"`
155
156 # function reset_time() {
157 #     CUR_TIME=`date +"%H:%M:%S"`
158 #     sudo date -s "$OLD_DATE $CUR_TIME"  >/dev/null 2>&1
159 # }
160 # trap reset_time INT TERM
161
162 #CUR_TIME=`date +"%H:%M:%S"`
163 #sudo date -s "03/11/2011 $CUR_TIME" >/dev/null 2>&1
164 do_qizx "$@"
165 #reset_time