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