Removes unnecessary debug messages
[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                 RUN_TESTS=1
122                 shift
123                 ;;
124
125                 '-j'|'--clean-journal')
126                 CLEAN_JOURNAL=1
127                 shift
128                 ;;
129
130                 *)
131                 echo "Invalid option, use '--help' for available options"
132                 exit 1
133                 ;;
134         esac
135 done
136
137 if [ "$BUILD_TYPE" != "" ]; then
138
139         echo $TEXT_INFO"Build type: "$BUILD_TYPE" chosen"
140
141         case "$BUILD_TYPE" in
142                 'initial')
143                 gbs build -A armv7l --include-all --ccache --define "jobs 4"
144                 exit_on_error
145                 ;;
146
147                 'fast')
148                 gbs build -A armv7l --include-all --noinit --ccache --keep-packs --define "jobs 4"
149                 exit_on_error
150                 ;;
151
152                 'no-tests')
153                 gbs build -A armv7l --include-all --noinit --ccache --keep-packs --define "_without_tests 1" --define "jobs 4"
154                 exit_on_error
155                 ;;
156
157                 *)
158                 echo $TEXT_ERROR"Cannot build, valid options for building are: initial, fast, no-tests"
159                 exit 1
160                 ;;
161         esac
162 fi
163
164 if [ "$INSTALL_PACKAGE" != "" ]; then
165         GBS_PATH="$HOME/GBS-ROOT/local/repos/public_mobile/armv7l/RPMS"
166         BASE_PACKAGE_NAME="$GBS_PATH/org.tizen.universal-switch-$VERSION-$RELEASE.armv7l.rpm"
167         TEST_PACKAGE_NAME="$GBS_PATH/org.tizen.universal-switch-tests-$VERSION-$RELEASE.armv7l.rpm"
168         TEST_LIB_PACKAGE_NAME="$HOME/GBS-ROOT/local/cache/*/gtest-[0-9]*"
169
170         case "$INSTALL_PACKAGE" in
171                 'base')
172                 if [ -f "$BASE_PACKAGE_NAME" ]; then
173                         BASE_FILE="$BASE_PACKAGE_NAME"
174                 else
175                         echo $TEXT_ERROR"Base package not found, check if it was built."
176                         exit 1
177                 fi
178                 ;;
179
180                 'tests')
181                 if [ -f "$TEST_PACKAGE_NAME" ]; then
182                         TEST_FILE="$TEST_PACKAGE_NAME"
183                         LIB_FILE="$TEST_LIB_PACKAGE_NAME"
184                 else
185                         echo $TEXT_ERROR"Test package not found, check if it was built."
186                         exit 1
187                 fi
188                 ;;
189
190                 'all')
191                 if [ -f "$BASE_PACKAGE_NAME" -a -f "$TEST_PACKAGE_NAME" ]; then
192                         BASE_FILE="$BASE_PACKAGE_NAME"
193                         TEST_FILE="$TEST_PACKAGE_NAME"
194                         LIB_FILE="$TEST_LIB_PACKAGE_NAME"
195                 else
196                         echo $TEXT_ERROR"Not all packages exist, check if they were built."
197                         exit 1
198                 fi
199                 ;;
200
201                 *)
202                 echo $TEXT_ERROR"Cannot install, valid options for installing are: base, tests, all"
203                 exit 1
204                 ;;
205         esac
206
207         check_if_target_connected
208
209         echo $TEXT_INFO"Following packages will be installed: $BASE_FILE $TEST_FILE $LIB_FILE"
210         rpm_install "$BASE_FILE" "$TEST_FILE" $LIB_FILE
211 fi
212
213 if [ $CLEAN_JOURNAL -eq 1 ]; then
214         check_if_target_connected
215         sdb root on
216         sdb shell 'journalctl --vacuum-size=1K'
217 fi
218
219 if [ $RUN_TESTS -eq 1 ]; then
220         check_if_target_connected
221
222         echo $TEXT_INFO"Setting vconf keys..."
223         dir="$(dirname "$0")"
224         "$dir"/utils/setVconfKeys.sh "accessibilityTests/"
225
226         sdb root on
227         sdb shell '
228                 set -e
229                 DATE=`date "+%F %X"`
230                 for i in /usr/apps/org.tizen.universal-switch-tests/no-ui-scenarios/*
231                 do
232                         $i
233                 done
234
235                 echo "Tests with Graphical User Interface"
236                 UI_PID=`app_launcher -s org.tizen.universal-switch-tests | sed "s/^.*pid \= \([[:digit:]]*\).*$/\1/"`
237                 journalctl --since "$DATE" -f | grep universal-switch-tests &
238                 while kill -0 $UI_PID 2> /dev/null
239                 do
240                         sleep 1
241                 done
242         '
243 fi