#!/usr/local/plan9/bin/rc

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


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

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

fn srcrun9p {
	if(test -e $rfile)
		rm $rfile
	9p ls -l rtest/plan9/sys/src/cmd/acme/look.c | sort | uniq | awk $lsformat >> $rfile
	9p read rtest/plan9/LICENSE | wc >> $rfile
	9p ls rtest/plan9/sys/src/cmd/acme | sort | uniq | wc  >> $rfile
}

fn wikirun9p {
	if(test -e $rfile)
		rm $rfile
	9p ls -l rtest/yup_yup/ | sort | uniq | awk $lsformat >> $rfile
	9p read  rtest/v9fs/history.txt | wc  >> $rfile
	9p ls  rtest/wince_ftp/1045856564/ | sort | uniq | wc  >> $rfile
}

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

echo CORRECT:
rfile=/tmp/correct
if(test -e $ns/rtest){
	rm -f $ns/rtest
}


srv -a $server rtest
wikirun9p
#srcrun9p


cat $rfile

for(i){
	rfile = /tmp/recov
	recovertest = $i
	echo testing $recovertest...
	rm -f $ns/rtest
	slay o.recover | rc
	n=`{echo $i|sed 's/ /_/g'}
	./o.recover -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 o.recover | rc
}

rm /tmp/correct
rm /tmp/recov
