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