• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -x
2
3# Start an X session, fire up some xterms and GL apps, then bounce them
4# all over the screen.
5
6# Copyright (C) 2003-2006 IBM
7#
8# This program is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License as
10# published by the Free Software Foundation; either version 2 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16# General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21# 02111-1307, USA.
22
23
24# X11 testing -- this is a daemon test!
25# Run for 20m
26TEST_DURATION=1200
27
28# Always start X.
29NEED_TO_START_X=1
30#if [ -z "$DISPLAY" ]; then
31#	NEED_TO_START_X=1
32#fi
33
34# Kill test if we don't want it.
35if [ -z "$DO_X_TESTS" -o "$DO_X_TESTS" == "0" ]; then
36	echo "X11 testing is off."
37	exit -1
38fi
39
40# Can we find the startx script?
41RAW_X_SERVER=0
42XSERVER_FILE=`which startx 2> /dev/null`
43if [ -z "$XSERVER_FILE" -o ! -x "$XSERVER_FILE" ]; then
44	RAW_X_SERVER=1
45	XSERVER_FILE=`which X 2> /dev/null`
46	if [ -z "$XSERVER_FILE" -o ! -x "$XSERVER_FILE" ]; then
47		echo "startx script not found."
48		exit -1
49	fi
50fi
51
52# Count X servers
53OLD_XSERVERS=`pgrep -l X | grep -v Xprt | wc -l`
54
55# Start X server
56if [ $NEED_TO_START_X -eq 1 ]; then
57	echo "xterm_stress: Starting X..."
58
59	rm -rf /var/log/Xorg.2.log /var/log/XFree86.2.log
60
61	export DISPLAY=:2
62	if [ $RAW_X_SERVER -eq 0 ]; then
63		$XSERVER_FILE -- $DISPLAY -ac vt9 &
64	else
65		$POUNDER_HOME/timed_loop $TEST_DURATION $XSERVER_FILE $DISPLAY -ac vt9 &
66	fi
67
68	while true; do
69		NEW_XSERVERS=`pgrep -l X | grep -v Xprt | wc -l`
70		if [ $NEW_XSERVERS -gt $OLD_XSERVERS ]; then
71			export XPID=`pgrep -l X -n | grep -v Xprt | awk -F " " '{print $1}'`
72			echo -n " -$XPID" >> $POUNDER_PIDFILE
73			break
74		fi
75	done
76fi
77
78trap 'kill -4 $XPID' 15
79
80# Did we see any failures?
81LOGFILE=`ls /var/log/X*.2.log`
82ERRORS=`egrep -ic "(fatal)" $LOGFILE`
83if [ $ERRORS -gt 0 ]; then
84	if [ $ERRORS -eq 255 ]; then
85		ERRORS=254
86	fi
87	cp $LOGFILE $POUNDER_TMPDIR/x-log-$XPID
88	kill -4 $XPID
89	exit $ERRORS
90fi
91
92# Now start the window manager if we couldn't find startx.
93if [ $NEED_TO_START_X -eq 1 -a $RAW_X_SERVER -eq 1 ]; then
94	sleep 5
95	echo "xterm_stress: Starting twm - 5s"
96	twm &
97fi
98
99# Sleep a little more so that the session can start before
100# we start flooding X with crud.
101sleep 15
102
103# sets the list delimiter to :
104IFS=:
105# Add some screensavers to the path (OpenGL testing)
106export PATH=$PATH:/usr/lib/xscreensaver:/usr/X11R6/lib/xscreensaver
107
108# command list
109cmd="dmesg:ls -l:cat /var/log/messages:dmesg:ls -l:cat /var/log/messages"
110xcmd="sproingies -fps -delay 0:flyingtoasters -fps -delay 0:glmatrix -fps -delay 0"
111
112# Begin logging
113xterm -geom 80x25+0+0 -e "bash -c $POUNDER_SRCDIR/dump_xserver_statm" &
114
115#start text-based programs
116for i in $cmd
117do
118	exe="while true; do $i; done"
119	xterm -geometry 80x25`$POUNDER_SRCDIR/randacoords/coords 600 400` -e "bash -c '$exe'" &
120	sleep 1
121done
122
123#start gui programs
124for i in $xcmd
125do
126	bash -c "$i" &
127	sleep 1
128done
129
130# Put up a top window for top monitoring.
131xterm -geom 100x9+0+0 -e top &
132echo "xterm_stress: Test started"
133
134# Now make the windows go bonkers!
135$POUNDER_SRCDIR/xbonkers/xbonkers -i 500 -s 10000 &
136
137# If we started X via startx, we need to wait 1200s and then
138# kill $XPID.
139if [ $RAW_X_SERVER -eq 0 ]; then
140	sleep $TEST_DURATION
141	kill -4 $XPID
142fi
143
144# Track the number of times we wait for X server to die.
145DIE_TIMEOUT_LOOPS=0
146
147# Loop until the X server goes away
148while true; do
149	XSERVERS=`pgrep -l X | grep -v Xprt | wc -l`
150	if [ $XSERVERS -lt $OLD_XSERVERS ]; then
151		# Did we see any failures?
152		LOGFILE=`ls /var/log/X*.2.log`
153		ERRORS=`egrep -ic "(fatal)" $LOGFILE`
154
155		# There will always be one fatal error--we killed X.
156		exit $((ERRORS - 1))
157	fi
158	if [ $DIE_TIMEOUT_LOOPS -gt 180 ]; then
159		# Three minutes; try something stronger.
160		echo "First attempt to kill X server failed; trying -9."
161		kill -9 $XPID
162	fi
163	if [ $DIE_TIMEOUT_LOOPS -gt 360 ]; then
164		# Six minutes.  Still not dead?  Abort script.
165		echo "Second attempt to kill X server failed.  Aborting."
166		exit -1
167	fi
168
169	OLD_XSERVERS=$XSERVERS
170	DIE_TIMEOUT_LOOPS=$((DIE_TIMEOUT_LOOPS + 1))
171	sleep 1
172done
173
174echo "ERROR: Jumped to somewhere where we should never be."
175# We're not supposed to get here.
176exit 254
177