0bc7f08c3e7cb2e65e1ad3ac0ba8812e29d2934d
[src/qa-testdefinitions.git] / common / scripts / application-lifecycle.sh
1 #!/bin/sh
2
3 set -x
4
5 export TERM=dumb
6 export COLUMNS=1000
7
8 AGLDRIVER=agl-driver
9
10 while [ $# -ge 1 ]
11 do
12         case $1 in
13         -b)
14                 shift
15                 BASEURL=$1
16                 shift
17         ;;
18         *)
19                 echo "Unknown argument $1"
20                 exit 1
21         ;;
22         esac
23 done
24
25 if [ -z "$BASEURL" ]; then
26         echo "$0: missing BASEURL"
27         echo "Usage: $0 -b BASEURL"
28         exit 1
29 fi
30
31 do_afm_util()
32 {
33         if [ $SERVICE_USER -eq 1 -o $APPLICATION_USER -eq 1 ];then
34                 su - $AGLDRIVER -c "afm-util $*"
35         else
36                 afm-util $*
37         fi
38         return $?
39 }
40
41 wget -q $BASEURL -O index.html
42 if [ $? -ne 0 ];then
43         echo "ERROR: Cannot wget $BASEURL"
44         exit 1
45 fi
46
47 grep -o '[a-z-]*.wgt' index.html | sort | uniq |
48 while read wgtfile
49 do
50         WGTNAME=$(echo $wgtfile | sed 's,.wgt$,,')
51         SERVICE_PLATFORM=0
52         SERVICE_USER=0
53         APPLICATION_USER=0
54         echo "DEBUG: fetch $wgtfile"
55         wget -q $BASEURL/$wgtfile
56         if [ $? -ne 0 ];then
57                 echo "ERROR: wget from $BASEURL/$wgtfile"
58                 continue
59         fi
60
61         echo "DEBUG: analyse wgt file"
62         unzip $wgtfile
63         if [ $? -ne 0 ];then
64                 # TODO Do not fail yet, busybox unzip seems to "fail with success" when checking CRC
65                 echo "ERROR: cannot unzip $wgtfile"
66         fi
67         if [ -f config.xml ];then
68                 grep hidden config.xml
69                 if [ $? -eq 0 ];then
70                         echo "DEBUG: hidden package"
71                 else
72                         echo "DEBUG: not hidden package"
73                 fi
74                 # a service sets urn:AGL:widget:provided-api
75                 grep "urn:AGL:widget:provided-api" config.xml
76                 if [ $? -eq 0 ] ; then
77                     # we are a service, now determine the scope ...
78                     grep "urn:AGL:permission::partner:scope-platform" config.xml
79                     if [ $? -eq 0 ];then
80                         SERVICE_PLATFORM=1
81                     else
82                         SERVICE_USER=1
83                     fi
84                 else
85                     # we are an application
86                     APPLICATION_USER=1
87                     # no other type known (yet)
88                 fi
89         else
90                 echo "DEBUG: fail to unzip"
91         fi
92
93         echo "DEBUG: list current pkgs"
94         # TODO mktemp
95         LIST='list'
96         afm-util list --all > $LIST
97         if [ $? -ne 0 ];then
98                 echo "ERROR: afm-util list exit with error"
99                 continue
100         fi
101         if [ ! -s "$LIST" ];then
102                 echo "ERROR: afm-util list is empty"
103                 continue
104         fi
105
106         echo "DEBUG: check presence of $WGTNAME"
107         NAMEID=$(grep id\\\":\\\"${WGTNAME}@ $LIST | cut -d\" -f4 | cut -d\\ -f1)
108         if [ ! -z "$NAMEID" ];then
109                 echo "DEBUG: $WGTNAME already installed as $NAMEID"
110                 # need to kill then deinstall
111                 afm-util ps --all | grep -q $WGTNAME
112                 if [ $? -eq 0 ];then
113                         echo "DEBUG: kill $WGTNAME"
114                         afm-util kill $WGTNAME
115                         if [ $? -ne 0 ];then
116                                 echo "ERROR: afm-util kill"
117                                 lava-test-case afm-util-pre-kill-$WGTNAME --result fail
118                                 continue
119                         else
120                                 lava-test-case afm-util-pre-kill-$WGTNAME --result pass
121                         fi
122                 else
123                         echo "DEBUG: no need to kill $WGTNAME"
124                 fi
125
126                 echo "DEBUG: deinstall $WGTNAME"
127                 afm-util remove $NAMEID
128                 if [ $? -ne 0 ];then
129                         echo "ERROR: afm-util remove"
130                         lava-test-case afm-util-remove-$WGTNAME --result fail
131                         continue
132                 else
133                         lava-test-case afm-util-remove-$WGTNAME --result pass
134                 fi
135         else
136                 echo "DEBUG: $WGTNAME not installed"
137         fi
138         grep id $LIST
139
140         echo "DEBUG: install $wgtfile"
141         OUT="out"
142         afm-util install $wgtfile > $OUT
143         if [ $? -ne 0 ];then
144                 echo "ERROR: afm-util install"
145                 lava-test-case afm-util-install-$WGTNAME --result fail
146                 continue
147         else
148                 lava-test-case afm-util-install-$WGTNAME --result pass
149         fi
150         # message is like \"added\":\"mediaplayer@0.1\"
151         NAMEID=$(grep d\\\":\\\"${WGTNAME}@ $OUT | cut -d\" -f4 | cut -d\\ -f1)
152         if [ -z "$NAMEID" ];then
153                 echo "ERROR: Cannot get nameid"
154                 continue
155         fi
156         echo "DEBUG: $WGTNAME is installed as $NAMEID"
157
158         afm-util list --all > $LIST
159         if [ $? -ne 0 ];then
160                 echo "ERROR: afm-util list exit with error"
161                 continue
162         fi
163         if [ ! -s "$LIST" ];then
164                 echo "ERROR: afm-util list is empty"
165                 continue
166         fi
167         echo "DEBUG: Verify that $WGTNAME is installed"
168         grep -q $NAMEID $LIST
169         if [ $? -ne 0 ];then
170                 echo "ERROR: $WGTNAME is not installed"
171                 # for debugging, give full output
172                 echo "DEBUG: start of list"
173                 cat $LIST
174                 echo "DEBUG: end of list"
175         fi
176
177         do_afm_util info $NAMEID
178         if [ $? -ne 0 ];then
179                 echo "ERROR: afm-util info"
180                 lava-test-case afm-util-info-$WGTNAME --result fail
181         else
182                 lava-test-case afm-util-info-$WGTNAME --result pass
183         fi
184
185         echo "DEBUG: check if we see the package with systemctl list-units (before start)"
186         systemctl list-units --full | grep "afm.*$WGTNAME"
187         echo "DEBUG: check if we see the package with systemctl -a (before start)"
188         systemctl -a |grep "afm.*$WGTNAME"
189
190         echo "DEBUG: start $NAMEID"
191         do_afm_util start $NAMEID > "rid"
192         if [ $? -ne 0 ];then
193                 echo "ERROR: afm-util start"
194                 lava-test-case afm-util-start-$WGTNAME --result fail
195                 continue
196         else
197                 lava-test-case afm-util-start-$WGTNAME --result pass
198         fi
199
200         echo "DEBUG: check if we see the package with systemctl list-units (after start)"
201         systemctl list-units --full | grep "afm.*$WGTNAME"
202         echo "DEBUG: check if we see the package with systemctl -a (after start)"
203         systemctl -a |grep "afm.*$WGTNAME"
204
205         echo "DEBUG: Get RID for $NAMEID"
206         PSLIST="pslist"
207         afm-util ps --all > $PSLIST
208         if [ $? -ne 0 ];then
209                 echo "ERROR: afm-util ps"
210                 lava-test-case afm-util-ps-$WGTNAME --result fail
211                 continue
212         else
213                 cat $PSLIST
214                 lava-test-case afm-util-ps-$WGTNAME --result pass
215         fi
216         # TODO, compare RID with the list in $PSLIST"
217         RID="$(cat rid)"
218
219         echo "DEBUG: status $NAMEID ($RID)"
220         do_afm_util status $RID
221         if [ $? -ne 0 ];then
222                 echo "ERROR: afm-util status"
223                 lava-test-case afm-util-status-$WGTNAME --result fail
224                 continue
225         else
226                 lava-test-case afm-util-status-$WGTNAME --result pass
227         fi
228
229         echo "DEBUG: kill $NAMEID ($RID)"
230         do_afm_util kill $NAMEID
231         if [ $? -ne 0 ];then
232                 echo "ERROR: afm-util kill"
233                 lava-test-case afm-util-kill-$WGTNAME --result fail
234                 continue
235         else
236                 lava-test-case afm-util-kill-$WGTNAME --result pass
237         fi
238
239         echo "DEBUG: start2 $NAMEID"
240         do_afm_util start $NAMEID
241         if [ $? -ne 0 ];then
242                 echo "ERROR: afm-util start2"
243                 lava-test-case afm-util-start2-$WGTNAME --result fail
244                 continue
245         else
246                 lava-test-case afm-util-start2-$WGTNAME --result pass
247         fi
248 done