Modified settings table. Added samble labels.
[irreco.git] / script / test.sh
blob99715653488eda82d8cd4f97d05f5f50516f9a26
1 #!/bin/bash
2 cd `dirname "$0"`
3 source variables.sh
4 scratchbox_need
6 test_main()
7 {
8 COMMAND="$1"
10 if [[ "$COMMAND" == "" ]]; then
11 echo "Error: You did not give me a command to run!"
12 test_usage
13 exit 1
16 #if [[ ! -e "$IRTRANS_SHLIB_DIR" ]]; then
17 # echo "Error: IRTrans dir does not exist!"
18 # exit 1
19 #fi
21 ARGS=("$@")
22 case "$COMMAND" in
23 --conf|conf) test_conf "${ARGS[@]:1}";;
24 --make|make) test_make "${ARGS[@]:1}";;
25 --test|test) test_test "${ARGS[@]:1}";;
26 --clean|clean) test_clean "${ARGS[@]:1}";;
27 --install|install|inst) test_install "${ARGS[@]:1}";;
28 --run|run) test_run "${ARGS[@]:1}";;
29 --runcheck|runcheck) test_runcheck "${ARGS[@]:1}";;
30 --run-in-stand-alone) test_run_in_stand_alone "${ARGS[@]:1}";;
31 --checklog|checklog) test_checklog "${ARGS[@]:1}";;
32 *) echo "Error: Unknown command \"$COMMAND\"";
33 test_usage;
34 exit 1;;
35 esac
40 test_usage()
42 echo "Usage: $SCRIPT_NAME COMMAND [ options ]"
45 test_test()
47 test_install
48 test_run
51 test_clean()
53 "$SCRIPT_DIR"/irreco.sh clean
54 check_exit_code "$?"
56 "$SCRIPT_DIR"/backend.sh all clean
57 check_exit_code "$?"
59 print_title "CLEAN INSTALL DIR"
60 rm -rfv "$INSTALL_DIR"
62 #print_title "CLEAN SCRIPT TMP"
63 #rm -rfv "$SCRIPT_TMP_DIR/"*
66 test_conf()
68 #"$SCRIPT_DIR"/irtrans.sh untar "irtrans_noccf"
69 #check_exit_code "$?"
70 #"$SCRIPT_DIR"/irtrans.sh make "irtrans_noccf"
71 #check_exit_code "$?"
73 match_sb_target "$SCRIPT_TMP_DIR/irreco_sb_target"
74 if [[ "$?" != "0" ]]; then test_clean; fi
76 mkdir -p "$INSTALL_DIR"
78 if [ ! -f "$SCRIPT_PARENT_DIR"/irreco/Makefile ]; then
79 "$SCRIPT_DIR"/irreco.sh conf
80 check_exit_code "$?"
83 "$SCRIPT_DIR"/irreco.sh install
84 check_exit_code "$?"
86 #if [ ! -f "$SCRIPT_PARENT_DIR"/backend/irtrans/Makefile ]; then
87 # echo $IRTRANS_SHLIB_DIR
88 # echo $IRTRANS_IRSERVER_DIR
90 # "$SCRIPT_DIR"/backend.sh irtrans conf --prefix=/usr \
91 # "--with-irtrans=$IRTRANS_SHLIB_DIR"
92 # check_exit_code "$?"
93 #fi
95 #if [ ! -f "$SCRIPT_PARENT_DIR"/backend/mythtv/installroot.tmp ]; then
96 # "$SCRIPT_DIR"/backend.sh mythtv conf
97 # check_exit_code "$?"
98 #fi
100 #"$SCRIPT_DIR"/backend.sh dummy conf
101 #check_exit_code "$?"
102 #"$SCRIPT_DIR"/backend.sh lirc conf
103 #check_exit_code "$?"
104 #"$SCRIPT_DIR"/backend.sh mythtv conf
105 #check_exit_code "$?"
108 test_make()
110 test_conf
112 "$SCRIPT_DIR"/backend.sh all make
113 check_exit_code "$?"
115 #"$SCRIPT_DIR"/irreco.sh make
116 #check_exit_code "$?"
117 #"$SCRIPT_DIR"/backend.sh dummy make
118 #check_exit_code "$?"
119 #"$SCRIPT_DIR"/backend.sh lirc make
120 #check_exit_code "$?"
121 #"$SCRIPT_DIR"/backend.sh irtrans make
122 #check_exit_code "$?"
123 #"$SCRIPT_DIR"/backend.sh mythtv make
124 #check_exit_code "$?"
127 test_install()
129 test_make
131 "$SCRIPT_DIR"/backend.sh all install
132 check_exit_code "$?"
134 #cp "$IRTRANS_SHLIB_DIR/libIRTrans.so" "$INSTALL_DIR/lib"
135 #check_exit_code "$?"
137 #"$SCRIPT_DIR"/backend.sh dummy install
138 #check_exit_code "$?"
139 #"$SCRIPT_DIR"/backend.sh lirc install
140 #check_exit_code "$?"
141 #"$SCRIPT_DIR"/backend.sh irtrans install
142 #check_exit_code "$?"
143 #"$SCRIPT_DIR"/backend.sh mythtv install
144 #check_exit_code "$?"
145 #"$SCRIPT_DIR"/irtrans.sh install
146 #check_exit_code "$?"
149 test_run()
151 print_title "RUN"
152 test_run_check_dir
153 run-standalone.sh "$SCRIPT_PATH" --run-in-stand-alone "$@" \
154 2>&1 | tee "$RUN_LOG_FILE"
155 test_checklog
158 test_runcheck()
160 print_title "RUN AND CHECK"
161 test_run_check_dir
162 run-standalone.sh "$SCRIPT_PATH" --run-in-stand-alone "$@" \
163 2>&1 | tee "$RUN_LOG_FILE" \
164 | sed 's|^|_|' | test_run_check_enter_exit
167 test_run_check_dir()
169 # Prepare directories
170 mkdir -p "$INSTALL_DIR/lib"
171 check_exit_code "$?"
172 mkdir -p "$INSTALL_DIR/home/user/MyDocs"
173 check_exit_code "$?"
175 if [ ! -e "$INSTALL_DIR/home/$USER" ]; then
176 cd "$INSTALL_DIR/home"
177 ln -s user "$USER"
178 check_exit_code "$?"
179 cd "$OLDPWD"
183 test_run_in_stand_alone()
185 test_run_check_dir
187 # Change home dir
188 #declare -x HOME="$INSTALL_DIR/home/user"
190 # Fix paths
191 declare -x PATH="$PATH:$INSTALL_DIR/bin"
192 declare -x LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$INSTALL_DIR/lib"
193 declare -x G_SLICE="always-malloc"
194 declare -x G_DEBUG="gc-friendly"
196 # Goto homedir
197 cd "$INSTALL_DIR/home/user"
198 check_exit_code "$?"
200 # Start app
201 if [[ "$1" == "" ]]; then
202 echo "Running with default args."
203 "$INSTALL_DIR"/bin/irreco --debug=99
204 elif [[ "$1" == "strace" ]]; then
205 echo "Running with strace:" "$@"
206 strace "$INSTALL_DIR"/bin/irreco --debug=99
207 else
208 echo "Args:" "$@"
209 "$INSTALL_DIR"/bin/irreco "$@"
213 test_checklog()
215 test_is_log_check_needed "$@" && \
216 cat "$RUN_LOG_FILE" | sed 's|^|_|' | test_run_check_enter_exit
220 # Run some simple checks on the run_log to determinate if we need to do a
221 # thorough check of the log.
223 test_is_log_check_needed()
225 if [[ "$1" == "force" || "$1" == "--force" ]]; then
226 echo -e "\n___ LOG CHECK FORCED ___________________________________________________________"
227 return 0
231 # Dont check the log if core dump happend. In that case the log will
232 # be incorrect anyways..
234 tail "$RUN_LOG_FILE" -n 1 | grep 'core dumped' > /dev/null
235 if [[ "$?" == "0" ]]; then
236 return 1
239 grep '<-' "$RUN_LOG_FILE" | tail -n 1 | grep '^[^ ]' > /dev/null
240 if [[ "$?" != "0" ]]; then
241 echo -e "\n___ INDENT MISSMATCH, CHEKING LOG ______________________________________________"
242 return 0
245 grep 'INDENT COUNTER BELOW ZERO' "$RUN_LOG_FILE" > /dev/null
246 if [[ "$?" == "0" ]]; then
247 echo -e "\n___ INDENT MISSMATCH, CHEKING LOG ______________________________________________"
248 return 0
251 echo "... log indent appears to be fine."
252 return 1
256 # This amazing piece of script checks that irreco ENTER and RETURN messages
257 # match each other.
259 test_run_check_enter_exit()
261 PATTERN_ENTER='^[a-zA-Z]+[ ]*-> ([a-z_0-9]*)'
262 PATTERN_RETURN='^[a-zA-Z]+[ ]*<- ([a-z_0-9]*)'
263 DEBUG=0
266 while read -rs LINE; do
268 # Bash read command strips leading spaces, so we use sed to
269 # insert _ the the beginning of every line. This strips
270 # _ away, so we get the original string.
271 LINE="${LINE:1}"
272 echo "$LINE"
274 echo "$LINE" | egrep "$PATTERN_ENTER" > /dev/null
275 if [[ "$?" == "0" ]]; then
276 ((i++))
277 FUNC=`echo "$LINE" | egrep -o "$PATTERN_ENTER" \
278 | sed -r "s|$PATTERN_ENTER|\1|"`
279 if [ "$DEBUG" == "1" ]; then echo "Enter $i: $FUNC"; fi
280 INDENT[$i]="$FUNC"
281 else
283 echo "$LINE" | egrep "$PATTERN_RETURN" > /dev/null
284 if [[ "$?" == "0" ]]; then
286 FUNC=`echo "$LINE" | egrep -o "$PATTERN_RETURN" \
287 | sed -r "s|$PATTERN_RETURN|\1|"`
288 if [ "$DEBUG" == "1" ]; then echo "Return $i: $FUNC"; fi
289 if [[ "${INDENT[$i]}" != "$FUNC" ]]; then
290 echo -e "\n___ ERROR ______________________________________________________________________"
291 echo "Returned from \"$FUNC\""
292 echo "Instead of \"${INDENT[$i]}\""
293 exit 1
296 ((i--))
301 done
303 if [[ "${INDENT[$i]}" != "" ]]; then
304 echo -e "\n___ ERROR ______________________________________________________________________"
305 echo "Did not return from \"${INDENT[$i]}\""
306 echo "Program probably crashed inside of \"${INDENT[$i]}\""
307 exit 1
311 test_main "$@"