01d8231db22bbc03dc85411de5a88ce68803f3ae
[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
47 # e.g. qemu-system-arm takes loooong
48 sleep 10
49 echo "Waiting for compositor to initialize (+10sec)."
50
51 LOOP=20
52 while test $LOOP -ge 1 ; do
53
54   ( mv /tmp/next-log /tmp/prev-log > /dev/null 2>&1 ) || true
55   journalctl /usr/bin/agl-compositor --cursor-file=/tmp/agl-screenshot-cursor > /tmp/next-log 2>&1
56   if ! grep -q 'Usable area:' /tmp/next-log ; then
57   # e.g. qemu-system-arm takes loooong
58         echo "Waiting for compositor to initialize (+60sec). Loop: $LOOP"
59         sleep 60
60         LOOP="$(($LOOP-1))"
61         continue
62   fi
63   break
64 done
65
66 #read aw
67
68
69 # giving up now
70 if ! grep -q 'Usable area:' /tmp/next-log ; then
71         echo "Marker ('Usable area:') not found. Dumping log."
72         echo "##################################"
73         cat /tmp/first-log
74         cat /tmp/prev-log
75         cat /tmp/next-log
76         echo "##################################"
77         exit 127
78         #echo "CONTINUING ANYWAY !"
79 fi
80
81 AGL_SCREENSHOOTER=/usr/bin/agl-screenshooter
82
83 #su - $AGLDRIVER -c "..."
84 do_screenshot()
85 {
86         su - $AGLDRIVER -c "XDG_RUNTIME_DIR=/run/user/1001 $AGL_SCREENSHOOTER"
87         return $?
88 }
89
90
91 if [ -z "$AGL_SCREENSHOOTER" ]; then
92         echo "Failed to find agl-screenshooter. Compositor too old?"
93         exit 127
94 fi
95
96 #echo "Found agl-screenshoooter in $AGL_SCREENSHOOTER"
97 rm -rf /home/agl-driver/agl-screenshot-*.png
98
99 # give it a bit more time to display
100 #sleep 60
101
102 if do_screenshot ; then
103         echo "Screenshot taken"
104 else
105         echo "##################################"
106         journalctl --no-pager -a -b /usr/bin/agl-compositor
107         echo "##################################"
108         exit 127
109 fi
110
111 REF_IMAGE_SHA1SUM=`sha1sum ${REF_IMAGE} | awk -F ' ' '{print $1}'`
112 IMAGE_SHA1SUM=`sha1sum /home/agl-driver/agl-screenshot-*.png | awk -F ' ' '{print $1}'`
113
114 if [ "${REF_IMAGE_SHA1SUM}" == "${IMAGE_SHA1SUM}" ]; then
115         echo "Screenshot matches the reference image"
116         FINALRET=0
117 else
118         echo "Screenshot does not match the reference image"
119         FINALRET=127
120         for i in agl-screenshot-*.png ; do
121                 if [ -x ./artiproxy-upload.sh ];then
122                         ./artiproxy-upload.sh $i dumpjournal
123                 fi
124         done
125         echo "#########################"
126         journalctl -t agl-compositor
127         echo "#########################"
128         journalctl -b --no-pager -a
129         echo "#########################"
130 fi
131
132
133 # cleanup
134 sed -i '/activate-by-default=false/d' /etc/xdg/weston/weston.ini
135 sed -i '/hide-cursor=true/d' /etc/xdg/weston/weston.ini
136 #rm -rf /etc/systemd/system/weston@.service.d
137 rm -rf /etc/default/homescreen
138 systemctl daemon-reload
139 sync
140 sleep 2
141 systemctl restart agl-session@agl-driver.service
142
143 sleep 10
144
145 exit $FINALRET