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