Use full path to reference image
[src/qa-testdefinitions.git] / common / scripts / agl-screenshot-test.sh
1 #!/bin/bash
2
3 set -x
4
5 export TERM=dumb
6 export COLUMNS=1000
7
8 SCRIPTDIR=`dirname $(readlink -f $0)`
9 XDG_RUNTIME_DIR=/run/user/1001
10 AGLDRIVER=agl-driver
11
12 if [ -z $1 ] ; then
13     echo "No reference image passed"
14     exit 125
15 fi
16
17 REF_IMAGE=`readlink -f $1`
18
19 # go to output directory
20 cd /home/$AGLDRIVER
21
22
23
24
25 if [ -z "${REF_IMAGE}" ]; then
26         echo "No reference image passed"
27         exit 125
28 fi
29
30 if [ ! -f "${REF_IMAGE}" ]; then
31         echo "Reference image is not found"
32         exit 125
33 fi
34
35 # Enable the test picture and disable cursor and any other application from being displayed
36 sed -i '/^\[core\]/a activate-by-default=false' /etc/xdg/weston/weston.ini
37 # setup homescreen env variable
38 sed -i '/^\[core\]/a hide-cursor=true' /etc/xdg/weston/weston.ini
39 # enable red/green/blue test screen
40 echo 'HOMESCREEN_DEMO_CI=1' > /etc/default/homescreen
41 sync
42 systemctl daemon-reload || true
43 su - agl-driver -c 'export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1001/bus" ; systemctl --user daemon-reload' || true
44 sleep 2
45
46 # create initial journal cursor file
47 journalctl /usr/bin/agl-compositor --cursor-file=/tmp/agl-screenshot-cursor > /tmp/first-log 2>&1
48
49 # stop homescreen (shell) and launcher
50 su $AGLDRIVER -c 'XDG_RUNTIME_DIR=/run/user/1001/ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus systemctl --user stop homescreen'
51 su $AGLDRIVER -c 'XDG_RUNTIME_DIR=/run/user/1001/ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus systemctl --user stop launcher'
52 # restart agl-compositor
53 su $AGLDRIVER -c 'XDG_RUNTIME_DIR=/run/user/1001/ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus systemctl --user restart agl-compositor'
54 su $AGLDRIVER -c 'XDG_RUNTIME_DIR=/run/user/1001/ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus systemctl --user start homescreen'
55
56 # e.g. qemu-system-arm takes loooong
57 sleep 10
58 echo "Waiting for compositor to initialize (+10sec)."
59
60 LOOP=20
61 while test $LOOP -ge 1 ; do
62
63   ( mv /tmp/next-log /tmp/prev-log > /dev/null 2>&1 ) || true
64   journalctl /usr/bin/agl-compositor --cursor-file=/tmp/agl-screenshot-cursor > /tmp/next-log 2>&1
65   if ! grep -q 'Usable area:' /tmp/next-log ; then
66   # e.g. qemu-system-arm takes loooong
67         echo "Waiting for compositor to initialize (+60sec). Loop: $LOOP"
68         sleep 60
69         LOOP="$(($LOOP-1))"
70         continue
71   fi
72   break
73 done
74
75 #read aw
76
77
78 # giving up now
79 if ! grep -q 'Usable area:' /tmp/next-log ; then
80         echo "Marker ('Usable area:') not found. Dumping log."
81         echo "##################################"
82         cat /tmp/first-log
83         cat /tmp/prev-log
84         cat /tmp/next-log
85         echo "##################################"
86         exit 127
87         #echo "CONTINUING ANYWAY !"
88 fi
89
90 AGL_SCREENSHOOTER=/usr/bin/agl-screenshooter
91
92
93 #su - $AGLDRIVER -c "..."
94 do_screenshot()
95 {
96         su - $AGLDRIVER -c "XDG_RUNTIME_DIR=/run/user/1001 $AGL_SCREENSHOOTER -a"
97         return $?
98 }
99
100
101 if [ -z "$AGL_SCREENSHOOTER" ]; then
102         echo "Failed to find agl-screenshooter. Compositor too old?"
103         exit 127
104 fi
105
106 #echo "Found agl-screenshoooter in $AGL_SCREENSHOOTER"
107 rm -rf /home/agl-driver/agl-screenshot-*.png
108
109 # give it a bit more time to display
110 #sleep 60
111
112 su - $AGLDRIVER -c "XDG_RUNTIME_DIR=/run/user/1001 $AGL_SCREENSHOOTER -l"
113
114 if do_screenshot ; then
115         echo "Screenshot taken"
116 else
117         echo "##################################"
118         journalctl --no-pager -a -b /usr/bin/agl-compositor
119         echo "##################################"
120         exit 127
121 fi
122
123 ls agl-screenshot*
124
125 REF_IMAGE_SHA1SUM=`sha1sum ${REF_IMAGE} | awk -F ' ' '{print $1}'`
126
127 FINALRET=1
128
129
130 for SCREENSHOT in agl-screenshot-*.png ; do
131     IMAGE_SHA1SUM=`sha1sum $SCREENSHOT | awk -F ' ' '{print $1}'`
132
133     if [ "${REF_IMAGE_SHA1SUM}" == "${IMAGE_SHA1SUM}" ]; then
134         echo "A Screenshot matches the reference image"
135         FINALRET=0
136         break
137     else
138         echo "A Screenshot does not match the reference image"
139         FINALRET=127
140     fi
141
142 done
143
144 if [ $FINALRET != 0 ] ; then
145     for i in agl-screenshot-*.png ; do
146         ${SCRIPTDIR}/./artiproxy-upload.sh $i "$i"
147     done
148     journalctl -b --no-pager -a > journal.txt
149     ${SCRIPTDIR}/./artiproxy-upload.sh journal.txt journal.txt
150
151     echo "#########################"
152     cat /run/platform/display/*.log
153     echo "#########################"
154     set
155     echo "#########################"
156 fi
157
158 # cleanup
159 sed -i '/activate-by-default=false/d' /etc/xdg/weston/weston.ini
160 sed -i '/hide-cursor=true/d' /etc/xdg/weston/weston.ini
161 #rm -rf /etc/systemd/system/weston@.service.d
162 rm -rf /etc/default/homescreen
163 systemctl daemon-reload
164 sync
165 sleep 2
166 systemctl restart agl-session@agl-driver.service
167
168 sleep 10
169
170 exit $FINALRET