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