#!/bin/sh 
 
echo "You need to manually load lnet_selftest on all nodes"
echo "modprobe lnet_selftest"

the_usage()
{
        echo >&2
        echo "usage: `basename $0` -c client-nids -s server-nids [-r] [-w] [-n rpcs]" >&2
	cat <<EOF 2>&1
-c 		client nids
-s 		server nids
-r 		reads only
-w 		writes only
-n rpcs		max_rpcs_in_flight, defaults to 8

example:
lnet_selftest.sh -c "10.10.100.223@o2ib 10.10.100.224@o2ib" \
 -s "10.10.100.215@o2ib 10.10.100.216@o2ib" 

EOF
}

reads_only=0
writes_only=0
concurent=8 # 8 rpcs in flight by default
while getopts ":c:s:n:rw" opt; do
        case $opt in
        c)
                clients="$OPTARG"
                ;;
	r)
		reads_only=1
		;;
	w)	writes_only=1
		;;
        s)
                servers="$OPTARG"
                ;;
	n)	concurent=$OPTARG
		;;
        :)      
                echo "Option -$OPTARG requires an argument." >&2
                the_usage 
                exit 1
                ;;
        *)
                echo "Invalid option: -$OPTARG" >&2
                the_usage
                exit 1
                ;;
        esac
done

if [ -z "$clients" -o -z "$servers" ];then 
	the_usage
	exit 1
fi


export LST_SESSION=$$ 

trap "lst end_session" SIGINT SIGTERM 

echo "LST_SESSION=$LST_SESSION" 

lst new_session read/write 

lst add_group servers $servers
lst add_group readers $clients

# comment out any of these two if you don't want to duplex performance 
if [ $writes_only -eq 0 ]; then
	lst add_test --from readers --to servers brw write size=1M --concurrency $concurent
fi

if [ $reads_only -eq 0 ]; then
	lst add_test --from readers --to servers brw read  size=1M --concurrency $concurent
fi

lst run 

lst stat servers 

wait 

