screenshot-test: Extend startup delay and use no pager
[src/qa-testdefinitions.git] / common / scripts / agl-screenshot-test.sh
1 #!/bin/bash
2
3 set -x
4
5 XDG_RUNTIME_DIR=/run/user/200
6
7
8 REF_IMAGE="$1"
9
10 if [ -z "${REF_IMAGE}" ]; then
11         echo "No reference image passed"
12         exit 125
13 fi
14
15 if [ ! -f "${REF_IMAGE}" ]; then
16         echo "Reference image is not found"
17         exit 125
18 fi
19
20 # Enable the test picture and disable cursor and any other application from being displayed
21 sed -i '/^\[core\]/a activate-by-default=false' /etc/xdg/weston/weston.ini
22 # setup homescreen env variable
23 sed -i '/^\[core\]/a hide-cursor=true' /etc/xdg/weston/weston.ini
24 # enable red/green/blue test screen
25 echo 'HOMESCREEN_DEMO_CI=1' > /etc/default/homescreen
26 sync
27 systemctl daemon-reload
28 sleep 2
29
30 # create initial journal cursor file
31 journalctl /usr/bin/agl-compositor --cursor-file=/tmp/agl-screenshot-cursor > /tmp/first-log 2>&1
32
33 # restart weston@display
34 systemctl restart weston.service
35 # e.g. qemu-system-arm takes loooong
36 sleep 10
37 echo "Waiting for compositor to initialize (+10sec)."
38
39 LOOP=20
40 while test $LOOP -ge 1 ; do
41
42   ( mv /tmp/next-log /tmp/prev-log > /dev/null 2>&1 ) || true
43   journalctl /usr/bin/agl-compositor --cursor-file=/tmp/agl-screenshot-cursor > /tmp/next-log 2>&1
44   if ! grep -q 'Usable area:' /tmp/next-log ; then
45   # e.g. qemu-system-arm takes loooong
46         echo "Waiting for compositor to initialize (+60sec). Loop: $LOOP"
47         sleep 60
48         LOOP="$(($LOOP-1))"
49         continue
50   fi
51   break
52 done
53
54 #read aw
55
56
57 # giving up now
58 if ! grep -q 'Usable area:' /tmp/next-log ; then
59         echo "Marker ('Usable area:') not found. Dumping log."
60         echo "##################################"
61         cat /tmp/first-log
62         cat /tmp/prev-log
63         cat /tmp/next-log
64         echo "##################################"
65         exit 127
66         #echo "CONTINUING ANYWAY !"
67 fi
68
69 AGL_SCREENSHOOTER=/usr/bin/agl-screenshooter
70
71 if [ -z "$AGL_SCREENSHOOTER" ]; then
72         echo "Failed to find agl-screenshooter. Compositor too old?"
73         exit 127
74 fi
75
76 #echo "Found agl-screenshoooter in $AGL_SCREENSHOOTER"
77 rm -rf agl-screenshot-*.png
78
79 # give it a bit more time to display
80 sleep 30
81
82 if $AGL_SCREENSHOOTER; then
83         echo "Screenshot taken"
84 else
85         echo "##################################"
86         journalctl --no-pager -a -b /usr/bin/agl-compositor
87         echo "##################################"
88         exit 127
89 fi
90
91 REF_IMAGE_SHA1SUM=`sha1sum ${REF_IMAGE} | awk -F ' ' '{print $1}'`
92 IMAGE_SHA1SUM=`sha1sum agl-screenshot-*.png | awk -F ' ' '{print $1}'`
93
94 if [ "${REF_IMAGE_SHA1SUM}" == "${IMAGE_SHA1SUM}" ]; then
95         echo "Screenshot matches the reference image"
96         FINALRET=0
97 else
98         echo "Screenshot does not match the reference image"
99         FINALRET=127
100         for i in agl-screenshot-*.png ; do
101                 #set +x
102                 echo "################################################################"
103                 ( curl --upload-file "$i" https://transfer.sh/$(basename "$i") && echo "" ) || true
104                 echo "################################################################"
105                 #set -x
106         done
107         echo "#########################"
108         cat /run/platform/display/*.log
109         echo "#########################"
110         journalctl -b --no-pager -a
111         echo "#########################"
112 fi
113
114
115 # cleanup
116 sed -i '/activate-by-default=false/d' /etc/xdg/weston/weston.ini
117 sed -i '/hide-cursor=true/d' /etc/xdg/weston/weston.ini
118 #rm -rf /etc/systemd/system/weston@.service.d
119 rm -rf /etc/default/homescreen
120 systemctl daemon-reload
121 sync
122 sleep 2
123 systemctl restart weston.service
124 sleep 10
125
126 exit $FINALRET