#!/bin/rc

rfile=/tmp/nofile
lsformat='{$3="X"; $9="X"; print}'	# $3 and $9 change a lot

server=sources.cs.bell-labs.com
#server='net!plan9.bell-labs.com!wiki'

if(~ $#* 0)
	*=(`{seq 2 30})	# okay that 1 doesn't work

fn srcrun9p {
	if(test -e $rfile)
		rm $rfile
	mount /srv/rtest /n/sources
	ls -l /n/sources/plan9/sys/src/cmd/acme/look.c | sort | uniq | awk $lsformat >> $rfile
	cat /n/sources/plan9/LICENSE | wc  >> $rfile
	ls /n/sources/plan9/sys/src/cmd/acme | sort | uniq | wc  >> $rfile
	unmount /n/sources
}

fn wikirun9p {
	if(test -e $rfile)
		rm $rfile
	mount /srv/rtest /n/wiki
	ls -l /n/wiki/yup_yup/ | sort | uniq | awk $lsformat >> $rfile
	cat /n/wiki/v9fs/history.txt | wc  >> $rfile
	ls /n/wiki/wince_ftp/1045856564/ | sort | uniq | wc  >> $rfile
	unmount /n/wiki
}

#if(test -e logp9/errors)
#	rm logp9/errors

echo CORRECT:
rfile=/tmp/correct
if(test -e /srv/test)
	rm -f /srv/rtest


srv -a $server rtest
#wikirun9p
srcrun9p


cat $rfile

for(i){
	rfile = /tmp/recov
	recovertest = $i
	echo testing $recovertest...
	rm -f /srv/rtest
	slay 8.out | rc
	n=`{echo $i|sed 's/ /_/g'}
	8.out -d $server rtest > logp9/log.$n >[2=1]
	echo $status
	srcrun9p
	#wikirun9p
	if (! diff /tmp/recov /tmp/correct ){
		echo error in $i | tee >> logp9/errors
		cat $rfile
	} 
	if not{
		rm logp9/log.$n
		echo ok
	}
	slay 8.out | rc
}

rm /tmp/correct
rm /tmp/recov
