#!/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 "./peer1 $opt1"
    rm -f $ref
    ./peer1${exe} $opt1 &
    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 "./peer2 $opt2 100"
    ./peer2 $opt2 100
}

#
# Run a test with all possible peer1 concurrency models
#
runmulti()
{
    opt1="-ORBreactive -OAreactive"
    run
    if test -n "$with_jtc"
    then
	opt1="-ORBthreaded -OAthread_per_request"
	run
	opt1="-ORBthreaded -OAthread_pool 50"
	run
    fi
}

#
# Run performance test for all concurrency models that allow nested
# method calls
#
opt2="-ORBreactive -OAreactive"
runmulti
if test -n "$with_jtc"
then
    opt2="-ORBthreaded -OAthread_per_request"
    runmulti
    opt2="-ORBthreaded -OAthread_pool 50"
    runmulti
fi

#
# Deactivate everything
#
deactivate
