Fixes to TTS
[platform/core/accessibility/universal-switch.git] / project-tool
1 #!/bin/sh
2
3 TEXT_ERROR='\033[0;31mError: \033[0m'
4 TEXT_INFO='\033[0;32mInfo: \033[0m'
5
6 print_help()
7 {
8         echo "usage: $0 [-h] [-b [BUILT_TYPE]] [-i [PACKAGE]] [-t]\n"
9         echo "Tool for easy building, installing and running tests of Universal Switch."
10         echo "Requires getopt, gbs and sdb.\n"
11         echo "Options:"
12         echo "-h,--help                 print this message"
13         echo "-bBUILT_TYPE,--build=BUILT_TYPE   build repository using GBS, available types are: 'initial', 'fast', 'no-tests', default value is 'fast'"
14         echo "-iPACKAGE,--install=PACKAGE       install package on connected target, available packages are: 'base', 'tests', 'all', default value is 'all'"
15         echo "-t,--run-tests                    run tests on connected target"
16         echo "-j,--clean-journal                vacuum systemd journal on target"
17 }
18
19 check_if_sdb_exist()
20 {
21         which sdb 1>/dev/null
22         if [ "$?" -ne 0 ]; then
23                 echo $TEXT_ERROR"Command sdb cannot be found, check if it is installed and its directory is added to PATH"
24                 exit 1
25         fi
26 }
27
28 check_if_target_connected()
29 {
30         check_if_sdb_exist
31
32         sdb devices | grep "device " 1>/dev/null
33         if [ "$?" -ne 0 ]; then
34                 echo $TEXT_ERROR"Target not connected"
35                 exit 1
36         fi
37 }
38
39 rpm_install()
40 {
41         TMP=`mktemp -d`
42
43         check_if_target_connected
44         sdb root on
45         sdb -d shell mount -o remount,rw /
46
47         cp "$@" "$TMP" 2>/dev/null
48
49         sdb push "$TMP" "$TMP"
50         sdb -d shell rpm -Uvh --force "$TMP"/*
51 }
52
53 exit_on_error()
54 {
55         if [ $? -eq 1 ]; then
56                 exit 1
57         fi
58 }
59
60 RUN_TESTS=0
61 CLEAN_JOURNAL=0
62 DEFAULT_BUILT_TYPE="fast"
63 DEFAULT_INSTALL_TYPE="all"
64 VERSION=`awk '/Version/ {print $2}' packaging/org.tizen.universal-switch.spec`
65 RELEASE=`awk '/Release/ {print $2}' packaging/org.tizen.universal-switch.spec`
66
67 ARGUMENTS=`getopt -o hb::i::tj -l help,build::,install::,run-tests,clean-journal -n "$0" -- "$@"`
68 if [ $? -ne 0 ];
69 then
70     print_help;
71 fi
72
73 eval set -- "$ARGUMENTS"
74
75 while [ $# -gt 0 ]; do
76         key="$1"
77
78         case "$key" in
79                 --)
80                 shift
81                 break
82                 ;;
83
84                 '-h'|'--help')
85                 print_help
86                 exit 0
87                 ;;
88
89                 '-b'|'--build')
90                 case "$2" in
91                         "")
92                         BUILD_DIR="$HOME/GBS-ROOT/local/BUILD-ROOTS/scratch.armv7l.0/home/abuild/rpmbuild/BUILD/org.tizen.universal-switch-$VERSION"
93                         if [ -d "$BUILD_DIR" ]; then
94                                 BUILD_TYPE="fast"
95                         else
96                                 BUILD_TYPE="initial"
97                         fi
98                         shift 2
99                         ;;
100
101                         *)
102                         BUILD_TYPE="$2"
103                         shift 2
104                         ;;
105                 esac ;;
106
107                 '-i'|'--install')
108                 case "$2" in
109                         "")
110                         INSTALL_PACKAGE="$DEFAULT_INSTALL_TYPE"
111                         shift 2
112                         ;;
113
114                         *)
115                         INSTALL_PACKAGE="$2"
116                         shift 2
117                         ;;
118                 esac ;;
119
120                 '-t'|'--run-tets')
121                 sdb -d shell mount -o remount,rw /
122                 sdb push "tests/dbustests.conf" "/etc/dbus-1/system.d/"
123                 sdb -d shell killall -HUP dbus-daemon
124                 RUN_TESTS=1
125                 shift
126                 ;;
127
128                 '-j'|'--clean-journal')
129                 CLEAN_JOURNAL=1
130                 shift
131                 ;;
132
133                 *)
134                 echo "Invalid option, use '--help' for available options"
135                 exit 1
136                 ;;
137         esac
138 done
139
140 if [ "$BUILD_TYPE" != "" ]; then
141
142         echo $TEXT_INFO"Build type: "$BUILD_TYPE" chosen"
143
144         case "$BUILD_TYPE" in
145                 'initial')
146                 gbs build -A armv7l --include-all --ccache --define "jobs 4"
147                 exit_on_error
148                 ;;
149
150                 'fast')
151                 gbs build -A armv7l --include-all --noinit --ccache --keep-packs --define "jobs 4"
152                 exit_on_error
153                 ;;
154
155                 'no-tests')
156                 gbs build -A armv7l --include-all --noinit --ccache --keep-packs --define "_without_tests 1" --define "jobs 4"
157                 exit_on_error
158                 ;;
159
160                 *)
161                 echo $TEXT_ERROR"Cannot build, valid options for building are: initial, fast, no-tests"
162                 exit 1
163                 ;;
164         esac
165 fi
166
167 if [ "$INSTALL_PACKAGE" != "" ]; then
168         GBS_PATH="$HOME/GBS-ROOT/local/repos/public_mobile/armv7l/RPMS"
169         BASE_PACKAGE_NAME="$GBS_PATH/org.tizen.universal-switch-$VERSION-$RELEASE.armv7l.rpm"
170         TEST_PACKAGE_NAME="$GBS_PATH/org.tizen.universal-switch-tests-$VERSION-$RELEASE.armv7l.rpm"
171         TEST_LIB_PACKAGE_NAME="$HOME/GBS-ROOT/local/cache/*/gtest-[0-9]*"
172
173         case "$INSTALL_PACKAGE" in
174                 'base')
175                 if [ -f "$BASE_PACKAGE_NAME" ]; then
176                         BASE_FILE="$BASE_PACKAGE_NAME"
177                 else
178                         echo $TEXT_ERROR"Base package not found, check if it was built."
179                         exit 1
180                 fi
181                 ;;
182
183                 'tests')
184                 if [ -f "$TEST_PACKAGE_NAME" ]; then
185                         TEST_FILE="$TEST_PACKAGE_NAME"
186                         LIB_FILE="$TEST_LIB_PACKAGE_NAME"
187                 else
188                         echo $TEXT_ERROR"Test package not found, check if it was built."
189                         exit 1
190                 fi
191                 ;;
192
193                 'all')
194                 if [ -f "$BASE_PACKAGE_NAME" -a -f "$TEST_PACKAGE_NAME" ]; then
195                         BASE_FILE="$BASE_PACKAGE_NAME"
196                         TEST_FILE="$TEST_PACKAGE_NAME"
197                         LIB_FILE="$TEST_LIB_PACKAGE_NAME"
198                 else
199                         echo $TEXT_ERROR"Not all packages exist, check if they were built."
200                         exit 1
201                 fi
202                 ;;
203
204                 *)
205                 echo $TEXT_ERROR"Cannot install, valid options for installing are: base, tests, all"
206                 exit 1
207                 ;;
208         esac
209
210         check_if_target_connected
211
212         echo $TEXT_INFO"Following packages will be installed: $BASE_FILE $TEST_FILE $LIB_FILE"
213         rpm_install "$BASE_FILE" "$TEST_FILE" $LIB_FILE
214 fi
215
216 if [ $CLEAN_JOURNAL -eq 1 ]; then
217         check_if_target_connected
218         sdb root on
219         sdb shell 'journalctl --vacuum-size=1K'
220 fi
221
222 if [ $RUN_TESTS -eq 1 ]; then
223         check_if_target_connected
224
225         echo $TEXT_INFO"Setting vconf keys..."
226         dir="$(dirname "$0")"
227         "$dir"/utils/setVconfKeys.sh "accessibilityTests/"
228
229         sdb root on
230         sdb shell '
231                 set -e
232                 DATE=`date "+%F %X"`
233                 for i in /usr/apps/org.tizen.universal-switch-tests/no-ui-scenarios/*
234                 do
235                         $i
236                 done
237
238                 echo "Tests with Graphical User Interface"
239                 UI_PID=`app_launcher -s org.tizen.universal-switch-tests | sed "s/^.*pid \= \([[:digit:]]*\).*$/\1/"`
240                 journalctl --since "$DATE" -f | grep universal-switch-tests &
241                 while kill -0 $UI_PID 2> /dev/null
242                 do
243                         sleep 1
244                 done
245         '
246 fi