summaryrefslogtreecommitdiffstats
path: root/common/scripts/agl-screenshot-test.sh
blob: 030ef34e23ae713dc093879fe953101806df212b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash

set -x

export TERM=dumb
export COLUMNS=1000

SCRIPTDIR=`dirname $(readlink -f $0)`
XDG_RUNTIME_DIR=/run/user/1001
AGLDRIVER=agl-driver

if [ -z $1 ] ; then
    echo "No reference image passed"
    exit 125
fi

REF_IMAGE=`readlink -f $1`

# go to output directory
cd /home/$AGLDRIVER




if [ -z "${REF_IMAGE}" ]; then
	echo "No reference image passed"
	exit 125
fi

if [ ! -f "${REF_IMAGE}" ]; then
	echo "Reference image is not found"
	exit 125
fi

# Enable the test picture and disable cursor and any other application from being displayed
sed -i '/^\[core\]/a activate-by-default=false' /etc/xdg/weston/weston.ini
# setup homescreen env variable
sed -i '/^\[core\]/a hide-cursor=true' /etc/xdg/weston/weston.ini
# enable red/green/blue test screen
echo 'HOMESCREEN_DEMO_CI=1' > /etc/default/homescreen
sync
systemctl daemon-reload || true
sleep 2

# create initial journal cursor file
journalctl /usr/bin/agl-compositor --cursor-file=/tmp/agl-screenshot-cursor > /tmp/first-log 2>&1

# stop homescreen (shell) and launcher
systemctl stop homescreen.service
systemctl stop launcher.service
# restart agl-compositor
systemctl restart agl-compositor.service
systemctl start homescreen.service

# e.g. qemu-system-arm takes loooong
sleep 10
echo "Waiting for compositor to initialize (+10sec)."

LOOP=20
while test $LOOP -ge 1 ; do

  ( mv /tmp/next-log /tmp/prev-log > /dev/null 2>&1 ) || true
  journalctl /usr/bin/agl-compositor --cursor-file=/tmp/agl-screenshot-cursor > /tmp/next-log 2>&1
  if ! grep -q 'Usable area:' /tmp/next-log ; then
  # e.g. qemu-system-arm takes loooong
        echo "Waiting for compositor to initialize (+60sec). Loop: $LOOP"
	sleep 60
	LOOP="$(($LOOP-1))"
	continue
  fi
  break
done

#read aw


# giving up now
if ! grep -q 'Usable area:' /tmp/next-log ; then
	echo "Marker ('Usable area:') not found. Dumping log."
	echo "##################################"
	cat /tmp/first-log
	cat /tmp/prev-log
	cat /tmp/next-log
	echo "##################################"
        exit 127
	#echo "CONTINUING ANYWAY !"
fi

AGL_SCREENSHOOTER=/usr/bin/agl-screenshooter


#su - $AGLDRIVER -c "..."
do_screenshot()
{
	$AGL_SCREENSHOOTER -a
	return $?
}


if [ -z "$AGL_SCREENSHOOTER" ]; then
	echo "Failed to find agl-screenshooter. Compositor too old?"
	exit 127
fi

#echo "Found agl-screenshoooter in $AGL_SCREENSHOOTER"
rm -rf /home/agl-driver/agl-screenshot-*.png

# give it a bit more time to display
#sleep 60

$AGL_SCREENSHOOTER -l

if do_screenshot ; then
	echo "Screenshot taken"
else
	echo "##################################"
	journalctl --no-pager -a -b /usr/bin/agl-compositor
	echo "##################################"
	exit 127
fi

ls agl-screenshot*

REF_IMAGE_SHA1SUM=`sha1sum ${REF_IMAGE} | awk -F ' ' '{print $1}'`

FINALRET=1


for SCREENSHOT in agl-screenshot-*.png ; do
    IMAGE_SHA1SUM=`sha1sum $SCREENSHOT | awk -F ' ' '{print $1}'`

    if [ "${REF_IMAGE_SHA1SUM}" == "${IMAGE_SHA1SUM}" ]; then
	echo "A Screenshot matches the reference image"
	FINALRET=0
	break
    else
	echo "A Screenshot does not match the reference image"
	FINALRET=127
    fi

done

if [ $FINALRET != 0 ] ; then
    for i in agl-screenshot-*.png ; do
	${SCRIPTDIR}/./artiproxy-upload.sh $i "$i"
    done
    journalctl -b --no-pager -a > journal.txt
    ${SCRIPTDIR}/./artiproxy-upload.sh journal.txt journal.txt

    echo "#########################"
    cat /run/platform/display/*.log
    echo "#########################"
    set
    echo "#########################"
fi

# cleanup
sed -i '/activate-by-default=false/d' /etc/xdg/weston/weston.ini
sed -i '/hide-cursor=true/d' /etc/xdg/weston/weston.ini
#rm -rf /etc/systemd/system/weston@.service.d
rm -rf /etc/default/homescreen
systemctl daemon-reload
sync
sleep 2
systemctl restart agl-compositor.service
systemctl restart homescreen.service
systemctl restart launcher.service

sleep 10

exit $FINALRET