2010-09-16 14:39:50 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2010-09-17 03:56:34 +02:00
|
|
|
NGAMES=${NGAMES:-1}
|
2010-09-17 07:20:43 +02:00
|
|
|
NROOMS=${NROOMS:-1}
|
2010-09-21 07:08:51 +02:00
|
|
|
TIMEOUT=${TIMEOUT:-600}
|
2010-09-22 14:45:40 +02:00
|
|
|
HOST=${HOST:-localhost}
|
|
|
|
PORT=${PORT:-10997}
|
|
|
|
|
|
|
|
NAMES=(Brynn Ariela Kati Eric)
|
2010-09-17 03:56:34 +02:00
|
|
|
|
2010-09-18 16:35:02 +02:00
|
|
|
LOGDIR=$(basename $0)_logs
|
2010-09-20 14:33:58 +02:00
|
|
|
mv $LOGDIR /tmp/$LOGDIR_$$
|
2010-09-18 16:35:02 +02:00
|
|
|
mkdir -p $LOGDIR
|
|
|
|
|
2010-09-17 03:56:34 +02:00
|
|
|
USE_GTK=${USE_GTK:-FALSE}
|
|
|
|
|
|
|
|
if [ $USE_GTK = FALSE ]; then
|
|
|
|
PLAT_PARMS="-u -0"
|
|
|
|
fi
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "usage: [env=val *] $0" 1>&2
|
|
|
|
echo " current env variables and their values: " 1>&2
|
2010-09-22 14:45:40 +02:00
|
|
|
for VAR in NGAMES NROOMS USE_GTK TIMEOUT HOST PORT; do
|
2010-09-17 03:56:34 +02:00
|
|
|
echo "$VAR:" $(eval "echo \$${VAR}") 1>&2
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2010-09-16 14:39:50 +02:00
|
|
|
do_device() {
|
|
|
|
GAME=$1
|
|
|
|
DEV=$2
|
|
|
|
NDEVS=$3
|
2010-09-20 14:33:58 +02:00
|
|
|
|
|
|
|
LOG=${LOGDIR}/${GAME}_${DEV}_LOG.txt
|
|
|
|
rm -f $LOG
|
2010-09-17 07:20:43 +02:00
|
|
|
ROOM=ROOM_$((GAME%NROOMS))
|
2010-09-16 14:39:50 +02:00
|
|
|
|
|
|
|
FILE="GAME_${GAME}_${DEV}.xwg"
|
|
|
|
rm -f $FILE
|
|
|
|
for II in $(seq 2 $NDEVS); do
|
|
|
|
OTHERS="-N $OTHERS"
|
|
|
|
done
|
|
|
|
|
2010-09-21 07:08:51 +02:00
|
|
|
STOPTIME=$(($(date "+%s") + TIMEOUT))
|
2010-09-16 14:39:50 +02:00
|
|
|
while :; do
|
2010-09-17 03:56:34 +02:00
|
|
|
sleep $((RANDOM%5))
|
2010-09-22 14:45:40 +02:00
|
|
|
./obj_linux_memdbg/xwords -C $ROOM -r ${NAMES[$DEV]} $OTHERS \
|
|
|
|
-d dict.xwd -p $PORT -a $HOST -f $FILE -z 1:3 $PLAT_PARMS \
|
|
|
|
>/dev/null 2>>$LOG &
|
2010-09-16 14:39:50 +02:00
|
|
|
PID=$!
|
2010-09-20 14:33:58 +02:00
|
|
|
sleep $((RANDOM%10+5))
|
|
|
|
while :; do
|
|
|
|
kill $PID 2>/dev/null
|
|
|
|
[ -d /proc/$PID ] || break
|
|
|
|
sleep 1
|
|
|
|
done
|
2010-09-16 14:39:50 +02:00
|
|
|
|
2010-09-20 14:33:58 +02:00
|
|
|
if grep -q 'all remaining tiles' $LOG; then
|
2010-09-21 07:08:51 +02:00
|
|
|
echo -n "device $DEV in game $GAME succeeded ($LOG)"
|
2010-09-20 14:33:58 +02:00
|
|
|
date
|
2010-09-18 16:35:02 +02:00
|
|
|
break
|
2010-09-21 07:08:51 +02:00
|
|
|
elif [ $(date "+%s") -ge $STOPTIME ]; then
|
|
|
|
echo -n "timeout exceeded for device $DEV in game $GAME ($LOG)"
|
|
|
|
date
|
|
|
|
break
|
2010-09-22 14:45:40 +02:00
|
|
|
elif [ ! -d $LOGDIR ]; then
|
|
|
|
break;
|
2010-09-18 16:35:02 +02:00
|
|
|
fi
|
2010-09-16 14:39:50 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
do_game() {
|
|
|
|
INDEX=$1
|
|
|
|
NDEVS=$(($RANDOM%3+2))
|
|
|
|
|
|
|
|
for DEV in $(seq $NDEVS); do
|
2010-09-20 14:33:58 +02:00
|
|
|
do_device $INDEX $DEV $NDEVS &
|
2010-09-16 14:39:50 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2010-09-17 03:56:34 +02:00
|
|
|
while [ -n "$1" ]; do
|
|
|
|
case $1 in
|
|
|
|
*) usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
for GAME in $(seq 1 $NGAMES); do
|
2010-09-16 14:39:50 +02:00
|
|
|
do_game $GAME
|
|
|
|
done
|
2010-09-17 03:56:34 +02:00
|
|
|
|
|
|
|
wait
|
2010-09-20 14:33:58 +02:00
|
|
|
|
|
|
|
for LOG in $LOGDIR/*LOG.txt; do
|
|
|
|
echo -n "$LOG "
|
|
|
|
grep 'got_connect_cmd: connName' $LOG | \
|
|
|
|
sed 's,^.*connName: \"\(.*\)\"$,\1,' | \
|
|
|
|
sort -u
|
|
|
|
done
|