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