shithub: ridefs

ref: 51489f979a4b1a0df534f9b8d461314c8ad86483
dir: /test/

View raw version
#!/bin/rc

fn fail{ echo $1 >[1=2]; exit $1}

./6.out $* ||
	fail 'Crashed at startup'

cd /mnt/ride ||
	fail 'Not mounted'

ls . >/dev/null ||
	fail 'Mountpoint not readable'

cat ctl >/dev/null ||
	fail 'Could not read ctl'

x=`{grep debug ctl}
echo 'debug 1' >ctl ||
	fail 'Could not write ctl'

y=`{grep debug ctl}
~ $y(2) 1 ||
	fail 'Written and read ctl values differ'
echo debug $x(2) >ctl

cat clone >/dev/null ||
	fail 'Could not clone'

<clone {
	cd `{read} ||
		fail 'Could not cd to client'

	cat ctl >/dev/null ||
		fail 'Could not read client ctl'

	x=`{grep umask ctl}
	echo 'umask 0777' >ctl ||
		fail 'Could not write client ctl'

	y=`{grep umask ctl}
	~ $y(2) 0777 ||
		fail 'Written and read client ctl values differ'
	echo umask $x(2) >ctl

	cd .. ||
		fail 'Could not cd out of client directory'
}

n=`{read clone}
ls -d $n >[2]/dev/null &&
	fail 'Did not clean up closed client'


<clone {
	cd `{read}

	echo 'connect 192.168.11.17' >ctl ||
		fail 'Could not connect to server'

	<>io >[1=0] {
		~ `{wc -c rinfo} 0 &&
			fail 'Did not receive RIDE info'

		cat >/dev/null ||
			fail 'Did not receive initial message'

		echo -n '["Execute",{"text":"⍳5\n","trace":0}]' ||
			fail 'Could not send message'

		res='["AppendSessionOutput",{"result":"⍳5\n","type":14,"group":0}]'
		~ `{cat} $res ||
			fail 'Did not receive response'
	}
	cd ..
}

<clone {
	cd `{read}
	echo 'connect 192.168.11.17' >ctl

	<>io >[1=0] {
		msg='["Execute",{"text":"⍳5\n","trace":0}]'
		echo -n $msg || fail 'Could not send message'
	} & spid=$apid

	<>io >[1=0] {
		cat >/dev/null || fail 'Could not receive message'
	} & rpid=$apid

	wait $spid || fail $status
	wait $rpid || fail $status
}