#!/bin/bash

# Perform the suite of unit tests in standalone mode.
#
# * Ordered arguments for remote debugging only. 
#
# 1. debug = {debug}
# 2. remote_addr = {IP address}
# 3. remote_port = {port number}
# 4. user_id = {user id}
# 5. debug_lib_path = {debugging library path}

MOPS_HOME=/usr/local/MOPS_DEVEL
TESTING_BIN=/home/drchang/unit-testing/bin
TESTING_LIB=/home/drchang/unit-testing/lib
LOG_PATH=/home/drchang/logs

export $MOPS_HOME
cd $TESTING_BIN

# Obtain a generated name for the test instance.
TEST_INSTANCE_NAME=`perl ./get-test-instance-name.pl`
echo $TEST_INSTANCE_NAME

TEST_LOG_NAME="$TEST_LOG_PATH/unit-testing_$TEST_INSTANCE_NAME.log"

# Set environment variables.
export PERL5LIB=$TESTING_LIB/perl5:$MOPS_HOME/lib/perl5
export PATH=$MOPS_HOME/bin:$PATH

echo "PERL5LIB is $PERL5LIB"
echo "TEST_INSTANCE_NAME = $TEST_INSTANCE_NAME"

# Test the units.

echo $1
echo $2
echo $3
echo $4
echo $5

if [ "$1" = "debug" ]
then
    export PERLDB_OPTS="RemotePort=$2:$3"
    export DBGP_IDEKEY="$4"
    export PERL5LIB=$PERL5LIB:$5
    perl -d ./test-units.pl --test_instance_name=$TEST_INSTANCE_NAME --retrieve_storables=0 --write_to_database=0 --delete_on_finish=1
else
    perl ./test-units.pl --test_instance_name=$TEST_INSTANCE_NAME --retrieve_storables=0 --write_to_database=0 --delete_on_finish=1
fi
