Created Theme_Save_Dlg
[irreco.git] / script / test.sh
blob5dba87fb36d187825bef6dc58d51ecc035491635
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 "$?"
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
111 #"$SCRIPT_DIR"/irreco.sh make
112 #check_exit_code "$?"
113 "$SCRIPT_DIR"/backend.sh dummy make
114 check_exit_code "$?"
115 "$SCRIPT_DIR"/backend.sh lirc make
116 check_exit_code "$?"
117 #"$SCRIPT_DIR"/backend.sh irtrans make
118 #check_exit_code "$?"
119 "$SCRIPT_DIR"/backend.sh mythtv make
120 check_exit_code "$?"
123 test_install()
125 test_make
127 #cp "$IRTRANS_SHLIB_DIR/libIRTrans.so" "$INSTALL_DIR/lib"
128 #check_exit_code "$?"
130 "$SCRIPT_DIR"/backend.sh dummy install
131 check_exit_code "$?"
132 "$SCRIPT_DIR"/backend.sh lirc install
133 check_exit_code "$?"
134 #"$SCRIPT_DIR"/backend.sh irtrans install
135 #check_exit_code "$?"
136 "$SCRIPT_DIR"/backend.sh mythtv install
137 check_exit_code "$?"
138 #"$SCRIPT_DIR"/irtrans.sh install
139 #check_exit_code "$?"
142 test_run()
144 print_title "RUN"
145 test_run_check_dir
146 run-standalone.sh "$SCRIPT_PATH" --run-in-stand-alone "$@" \
147 2>&1 | tee "$RUN_LOG_FILE"
148 test_checklog
151 test_runcheck()
153 print_title "RUN AND CHECK"
154 test_run_check_dir
155 run-standalone.sh "$SCRIPT_PATH" --run-in-stand-alone "$@" \
156 2>&1 | tee "$RUN_LOG_FILE" \
157 | sed 's|^|_|' | test_run_check_enter_exit
160 test_run_check_dir()
162 # Prepare directories
163 mkdir -p "$INSTALL_DIR/lib"
164 check_exit_code "$?"
165 mkdir -p "$INSTALL_DIR/home/user/MyDocs"
166 check_exit_code "$?"
168 if [ ! -e "$INSTALL_DIR/home/$USER" ]; then
169 cd "$INSTALL_DIR/home"
170 ln -s user "$USER"
171 check_exit_code "$?"
172 cd "$OLDPWD"
176 test_run_in_stand_alone()
178 test_run_check_dir
180 # Change home dir
181 #declare -x HOME="$INSTALL_DIR/home/user"
183 # Fix paths
184 declare -x PATH="$PATH:$INSTALL_DIR/bin"
185 declare -x LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$INSTALL_DIR/lib"
186 declare -x G_SLICE="always-malloc"
187 declare -x G_DEBUG="gc-friendly"
189 # Goto homedir
190 cd "$INSTALL_DIR/home/user"
191 check_exit_code "$?"
193 # Start app
194 if [[ "$1" == "" ]]; then
195 echo "Running with default args."
196 "$INSTALL_DIR"/bin/irreco --debug=99
197 elif [[ "$1" == "strace" ]]; then
198 echo "Running with strace:" "$@"
199 strace "$INSTALL_DIR"/bin/irreco --debug=99
200 else
201 echo "Args:" "$@"
202 "$INSTALL_DIR"/bin/irreco "$@"
206 test_checklog()
208 test_is_log_check_needed "$@" && \
209 cat "$RUN_LOG_FILE" | sed 's|^|_|' | test_run_check_enter_exit
213 # Run some simple checks on the run_log to determinate if we need to do a
214 # thorough check of the log.
216 test_is_log_check_needed()
218 if [[ "$1" == "force" || "$1" == "--force" ]]; then
219 echo -e "\n___ LOG CHECK FORCED ___________________________________________________________"
220 return 0
224 # Dont check the log if core dump happend. In that case the log will
225 # be incorrect anyways..
227 tail "$RUN_LOG_FILE" -n 1 | grep 'core dumped' > /dev/null
228 if [[ "$?" == "0" ]]; then
229 return 1
232 grep '<-' "$RUN_LOG_FILE" | tail -n 1 | grep '^[^ ]' > /dev/null
233 if [[ "$?" != "0" ]]; then
234 echo -e "\n___ INDENT MISSMATCH, CHEKING LOG ______________________________________________"
235 return 0
238 grep 'INDENT COUNTER BELOW ZERO' "$RUN_LOG_FILE" > /dev/null
239 if [[ "$?" == "0" ]]; then
240 echo -e "\n___ INDENT MISSMATCH, CHEKING LOG ______________________________________________"
241 return 0
244 echo "... log indent appears to be fine."
245 return 1
249 # This amazing piece of script checks that irreco ENTER and RETURN messages
250 # match each other.
252 test_run_check_enter_exit()
254 PATTERN_ENTER='^[a-zA-Z]+[ ]*-> ([a-z_0-9]*)'
255 PATTERN_RETURN='^[a-zA-Z]+[ ]*<- ([a-z_0-9]*)'
256 DEBUG=0
259 while read -rs LINE; do
261 # Bash read command strips leading spaces, so we use sed to
262 # insert _ the the beginning of every line. This strips
263 # _ away, so we get the original string.
264 LINE="${LINE:1}"
265 echo "$LINE"
267 echo "$LINE" | egrep "$PATTERN_ENTER" > /dev/null
268 if [[ "$?" == "0" ]]; then
269 ((i++))
270 FUNC=`echo "$LINE" | egrep -o "$PATTERN_ENTER" \
271 | sed -r "s|$PATTERN_ENTER|\1|"`
272 if [ "$DEBUG" == "1" ]; then echo "Enter $i: $FUNC"; fi
273 INDENT[$i]="$FUNC"
274 else
276 echo "$LINE" | egrep "$PATTERN_RETURN" > /dev/null
277 if [[ "$?" == "0" ]]; then
279 FUNC=`echo "$LINE" | egrep -o "$PATTERN_RETURN" \
280 | sed -r "s|$PATTERN_RETURN|\1|"`
281 if [ "$DEBUG" == "1" ]; then echo "Return $i: $FUNC"; fi
282 if [[ "${INDENT[$i]}" != "$FUNC" ]]; then
283 echo -e "\n___ ERROR ______________________________________________________________________"
284 echo "Returned from \"$FUNC\""
285 echo "Instead of \"${INDENT[$i]}\""
286 exit 1
289 ((i--))
294 done
296 if [[ "${INDENT[$i]}" != "" ]]; then
297 echo -e "\n___ ERROR ______________________________________________________________________"
298 echo "Did not return from \"${INDENT[$i]}\""
299 echo "Program probably crashed inside of \"${INDENT[$i]}\""
300 exit 1
304 test_main "$@"