agl-screenshot-test.sh: Save the contents of the screenshooter
[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 XDG_RUNTIME_DIR=/run/user/1001
9 AGLDRIVER=agl-driver
10
11
12
13
14 REF_IMAGE="$1"
15
16 if [ -z "${REF_IMAGE}" ]; then
17         echo "No reference image passed"
18         exit 125
19 fi
20
21 if [ ! -f "${REF_IMAGE}" ]; then
22         echo "Reference image is not found"
23         exit 125
24 fi
25
26 # Enable the test picture and disable cursor and any other application from being displayed
27 sed -i '/^\[core\]/a activate-by-default=false' /etc/xdg/weston/weston.ini
28 # setup homescreen env variable
29 sed -i '/^\[core\]/a hide-cursor=true' /etc/xdg/weston/weston.ini
30 # enable red/green/blue test screen
31 echo 'HOMESCREEN_DEMO_CI=1' > /etc/default/homescreen
32 sync
33 systemctl daemon-reload || true
34 su - agl-driver -c 'export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1001/bus" ; systemctl --user daemon-reload' || true
35 sleep 2
36
37 # create initial journal cursor file
38 journalctl /usr/bin/agl-compositor --cursor-file=/tmp/agl-screenshot-cursor > /tmp/first-log 2>&1
39
40 # stop homescreen (shell) and launcher
41 su $AGLDRIVER -c 'XDG_RUNTIME_DIR=/run/user/1001/ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus systemctl --user stop homescreen'
42 su $AGLDRIVER -c 'XDG_RUNTIME_DIR=/run/user/1001/ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus systemctl --user stop launcher'
43 # restart agl-compositor
44 su $AGLDRIVER -c 'XDG_RUNTIME_DIR=/run/user/1001/ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus systemctl --user 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 start homescreen'
46 su $AGLDRIVER -c 'XDG_RUNTIME_DIR=/run/user/1001/ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus systemctl --user start launcher'
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 #su - $AGLDRIVER -c "..."
85 do_screenshot()
86 {
87         su - $AGLDRIVER -c "XDG_RUNTIME_DIR=/run/user/1001 $AGL_SCREENSHOOTER"
88         return $?
89 }
90
91
92 if [ -z "$AGL_SCREENSHOOTER" ]; then
93         echo "Failed to find agl-screenshooter. Compositor too old?"
94         exit 127
95 fi
96
97 #echo "Found agl-screenshoooter in $AGL_SCREENSHOOTER"
98 rm -rf /home/agl-driver/agl-screenshot-*.png
99
100 # give it a bit more time to display
101 #sleep 60
102
103 if do_screenshot ; then
104         echo "Screenshot taken"
105 else
106         echo "##################################"
107         journalctl --no-pager -a -b /usr/bin/agl-compositor
108         echo "##################################"
109         exit 127
110 fi
111
112 REF_IMAGE_SHA1SUM=`sha1sum ${REF_IMAGE} | awk -F ' ' '{print $1}'`
113 IMAGE_SHA1SUM=`sha1sum /home/agl-driver/agl-screenshot-*.png | awk -F ' ' '{print $1}'`
114
115 if [ "${REF_IMAGE_SHA1SUM}" == "${IMAGE_SHA1SUM}" ]; then
116         echo "Screenshot matches the reference image"
117         FINALRET=0
118 else
119         echo "Screenshot does not match the reference image"
120         FINALRET=127
121         for i in agl-screenshot-*.png ; do
122                 if [ -x ./artiproxy-upload.sh ];then
123                         ./artiproxy-upload.sh $i dumpjournal
124                 fi
125         done
126         echo "#########################"
127         journalctl -t agl-compositor
128         echo "#########################"
129         journalctl -b --no-pager -a
130         echo "#########################"
131 fi
132
133
134 # cleanup
135 sed -i '/activate-by-default=false/d' /etc/xdg/weston/weston.ini
136 sed -i '/hide-cursor=true/d' /etc/xdg/weston/weston.ini
137 #rm -rf /etc/systemd/system/weston@.service.d
138 rm -rf /etc/default/homescreen
139 systemctl daemon-reload
140 sync
141 sleep 2
142 systemctl restart agl-session@agl-driver.service
143
144 sleep 10
145
146 exit $FINALRET