#!/bin/sh
# @(#)LOAD.TEST version 3.7 created 6/19/96
# @(#)Copyright (c), 1987, 1996 StatSci, Inc.  All rights reserved.

echo
echo '========== Running static load verification'
echo "           `date`"
echo
echo 'NOTE: This test will be a bit noisy. Look for a PASS/FAIL at the end.'
echo

cd ${SHOME}/adm/verify/load

status=0

# Static load test. Here we make local.Sqpe as close as possible to the way
# customers will. So instead of using the stripped-down and generic
# ~stest/bin/Splus, we use $SPLUS_SCRIPT, which should point to a recently
# made Splus shell script resembling ones the customers would make.  The
# point is to check the 'ld' arguments in the Splus script, and also the $L
# libraries.

if test -z "$SPLUS_SCRIPT"; then echo "
Setenv SPLUS_SCRIPT to the path of an Splus shell script made after the sysgen.
The one in ~stest/bin is NO GOOD, since it won't have the correct values for
S_LIB_STATIC." >&2 ; exit 1; fi

PATH=`dirname $SPLUS_SCRIPT`:$PATH	# no need to export; see below
# So we get the real Splus shell script every time we (implicitly) do 'Splus',
# not the usual one in ~stest/bin.

# S_WORK should've been set in the top level CHECKINSTALL script.
S_WORK=${S_WORK-/tmp/data.$$}
rm -rf $S_WORK; mkdir $S_WORK

# To ensure that we use the Splus script defaults for relevant environment 
# variables like S_LIB_STATIC, and not any settings from the login shell, we 
# want to unset a lot of things here. Since Decstation and Apollo /bin/sh don't
# have 'unset', accomplish this with 'env -', which starts with an empty
# environment.

echo "env - \
	HOME=$HOME \
	SHOME=$SHOME \
	PATH=$PATH \
	S_WORK=$S_WORK \
	LM_LICENSE_FILE=$LM_LICENSE_FILE \
	$SPLUS_SCRIPT \${1+\"\$@\"}" \
	> /tmp/Splus.$$
chmod +x /tmp/Splus.$$
/tmp/Splus.$$  EXEC env | grep S_LIB_STATIC	# show us $S_LIB_STATIC

#rm -f CxFlip_?.? local.Sqpe
#cp $HOME/lib/src/misc/CxFlip_?.c .
if [ -r Makefile ] 
then 
	mv Makefile _Makefile
	trap "mv _Makefile Makefile" 0
fi
/tmp/Splus.$$ LOAD CxFlip_?.c || status=1

if [ $status -eq 0 ]
then
    echo '
    cat("prog.name: ", prog.name(), "\n", "load.date: ", load.date(), "\n", sep="")
    cat("\n\nStatic load test", 
            if (all(rev(unlist(.C("MyFlip", 1+2i, 3+4i, 5+6i, 7+8i))) ==
                    c(1+2i, 3+4i, 5+6i, 7+8i)))
    "passed.\n" else "FAILED.\n")
    ' | /tmp/Splus.$$ || status=1
fi

rm -rf CxFlip_?.[ao] local.Sqpe $S_WORK /tmp/Splus.$$

echo
if [ $status -eq 0 ]
then echo "---------- Finished 'load' verification: PASSED"
else echo "---------- Finished 'load' verification: FAILED"
fi

exit $status

