#!/bin/sh

#	testit - record configuration relevant to running emacspeak

#	usage: run this script and examine the output file "log.tcl"
#	author: Jim Van Zandt <jrv@vanzandt.mv.com>

rm -f log*

date >log.tcl
uname -a >>log.tcl

echo >>log.tcl
echo "----- device files: is the relevant file readable and writeable?" >>log.tcl
ls -l /dev/ttyS? /dev/dtlk /dev/audio* >>log.tcl 2>&1
echo "current user is `whoami`, who is a member of these groups: `groups`" >>log.tcl

echo >>log.tcl
efile=`which emacs`
echo "----- \"which emacs\" = $efile" >>log.tcl
emacs --version | head -1 >>log.tcl

echo >>log.tcl
efile=`which emacspeak`
echo "----- \"which emacspeak\" = $efile" >>log.tcl
head -25 $efile >>log.tcl

echo >>log.tcl
efile=`which tcl`
ver=`echo 'echo $tcl_patchLevel'|$efile`
echo "----- \"which tcl\" = $efile, which is patch level $ver" >>log.tcl

echo >>log.tcl
echo "----- exported Emacspeak environment variables" >>log.tcl
set | egrep '(EMAC|DTK)' >>log.tcl

if [ -f /etc/emacspeak.conf ]; then
  echo >>log.tcl
  echo "----- /etc/emacspeak.conf" >>log.tcl
  cat /etc/emacspeak.conf >>log.tcl; 
fi

echo >>log.tcl
efile=`which strace`
echo "----- \"which strace\" = $efile" >>log.tcl
if [ "$efile" = "" ]; then 
    echo "strace not installed" >>log.tcl
    echo "please install strace before running testit"
    exit 1
fi
strace -V >>log.tcl

strace -o log -ff -F -r -t -s 120 emacspeak  --batch --eval "\"(print 'ok)\"" .

for file in log  					\
    `grep -l 'execve.*tcl.*tcl' log* | head -1` 	\
    `grep -l 'execve.*ping-apollo' log* | tail -1`; do
  prog=`grep execve $file|sed -e 's/^.*("//' -e 's/".*$//'|tail -1`
  
  echo >>log.tcl
  echo "----- $file $prog" >>log.tcl
  grep '\$Id' $file |head |sed -e 's/^.*\$Id/$Id/' -e 's/\.\.\..*$/.../' >>log.tcl

  echo >>log.tcl
  grep execve  $file >>log.tcl
  echo "..." >>log.tcl
  #egrep '(read|write|select)' $file |tail -400 >>log.tcl
  tail -400 $file >>log.tcl
done

echo the emacspeak session log files are summarized in log.tcl
