#!/bin/sh
# **********************************************************************
#
# Copyright (c) 1999
# Object Oriented Concepts, Inc.
# Billerica, MA, USA
#
# All Rights Reserved
#
# **********************************************************************

#
# Try to find top-level directory
#
if test -f ob/include/OB/CORBA.h
then
    top_srcdir=ob
elif test -f include/OB/CORBA.h
then
    top_srcdir=.
elif test -f ../include/OB/CORBA.h
then
    top_srcdir=..
elif test -f ../../include/OB/CORBA.h
then
    top_srcdir=../..
elif test -f ../../../include/OB/CORBA.h
then
    top_srcdir=../../..
elif test -f ../../../../include/OB/CORBA.h
then
    top_srcdir=../../../..
else
    $echo "$0: can't find top-level directory"
    exit
fi

#
# Run standard init script
#
. $top_srcdir/../config/sh.init

#
# Check for JTC
#
with_jtc=
if test "$windows" = "yes"
then
    with_jtc=`grep "^WITH_JTC.*=.*yes" $top_srcdir/../config/Make.rules.mak`
else
    with_jtc=`grep "^#define HAVE_JTC 1" $top_srcdir/include/OB/Config.h`
fi

#
# The name of reference file
#
ref=I.ref

#
# Function to deactivate the test server
#
srvid=0
deactivate()
{
    if test $srvid -ne 0
    then
        kill $srvid
    fi

    exit
}
trap deactivate 1 2 3 4 5 6 7 8 10 12 13 14 15

#
# Run a test
#
run()
{
    if test $srvid -ne 0
    then
        kill $srvid > /dev/null 2>&1
	srvid=0
    fi

    $echo
    $echo "./server $cltopt $srvopt"
    rm -f $ref
    ./server${exe} $cltopt $srvopt &
    srvid=$!
    count=0
    while test ! -s $ref -a $count -lt 6
    do
	sleep 1
	count=`expr $count + 1`
    done
    if test ! -s $ref
    then
	$echo "$0: can't start the server!"
	exit
    fi

    $echo "./client $cltopt 1000"
    ./client $cltopt 1000
}

#
# Run a test with all client side concurrency models
#
runmulti()
{
    cltopt="-ORBblocking"
    run
    if test "$srvopt" = "-OAreactive"
    then
        cltopt="-ORBreactive"
        run
    fi
    if test -n "$with_jtc"
    then
        cltopt="-ORBthreaded"
        run
    fi
}

#
# Run performance test for all concurrency models
#
srvopt="-OAblocking"
runmulti
srvopt="-OAreactive"
runmulti
if test -n "$with_jtc"
then
    srvopt="-OAthreaded"
    runmulti
    srvopt="-OAthread_per_client"
    runmulti
    srvopt="-OAthread_per_request"
    runmulti
    srvopt="-OAthread_pool 1"
    runmulti
fi

#
# Deactivate everything
#
deactivate
