#! /bin/sh
#
# check - runs all the tests, verifies the answers and prints out the
#    test report and mails it off to nana-bug.
#
# Copyright (c) 1997 Phil Maker
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Id: checkall,v 1.15 1997/10/26 05:47:54 pjm Exp $

(
# fix the path (is this really necessary?)
PATH=../src:.:${PATH}

MACHENV="`whoami`@`uname -n` `uname -m -s -r` `date`"

echo "* check: checking nana installation"
echo "* versions" `../config.guess` gcc-`gcc --version` \
	    gdb-`gdb --version |  awk '{print $2 }'` \
	    "`fgrep NANA_NAME ../src/nana-config.h | 
	      awk '{ print $3 }'`"
echo "* machine" `uname -m -s -r`
echo "* date" `date`
echo "* user" `whoami`@`uname -n`

echo "* typical execution time is about 10 minutes on a 100mhz pc"

echo "** testing C libraries using gcc and various optimisation flags"
for file in selftest.c Q.c I.c L.c DI.c DL.c DS.c
do
  for cflags in "" "-O" "-O2" "-O3"
  do
    echo "*** $file using gcc $cflags"
    nana-clg -I../src -I. $cflags $file | check.awk $file "gcc $cflags"
  done
done

echo "** testing C++ libraries using g++ and various optimisation flags"
for file in selftest.c eiffel.cc Qstl.cc
do
  for cflags in "" "-O" "-O2" "-O3"
  do
    echo "*** $file using g++ $cflags"
    NANACC=g++ nana-clg -I../src -I. -DEIFFEL_CHECK=CHECK_ALL $cflags $file | check.awk $file "g++ $cflags"
  done
done

echo "** testing C libraries using g++ and various optimisation flags"
# since C is a subset of C++, well sort of anyway
for file in selftest.c Q.c I.c L.c DI.c DL.c DS.c
do
  for cflags in "" "-O" "-O2" "-O3"
  do
    echo "*** $file using g++ $cflags"
    NANACC=g++ nana-clg -I../src -I. $cflags $file | check.awk $file "g++ $cflags"
  done
done

echo "** bash testing gdb with many breakpoints"

echo "*** manyDL.c"
runtest manyDL.c -I. -I../src ../src/libnana.a

echo "*** manyDI.c"
runtest manyDI.c -I. -I../src ../src/libnana.a 

echo "** time measurement"

echo "*** now.c - timing measurements"
nana-clg -I../src now.c ../src/libnana.a

echo "*** Ltime.c - timestamping log messages"
nana-clg -I../src Ltime.c ../src/libnana.a

echo "**** Ltime.c - redefining format"
nana-clg \
  -DL_SHOW_TIME_FORMAT=\"%8.2lfsec:\" -I../src Ltime.c ../src/libnana.a

echo "**** Ltime.c redefining now as a counter starting at 1000"
# since we are using a counter the output is always the same so
# we can use runtest (unlinke previous few tests).
runtest L_time.c -DL_SHOW_TIME_FORMAT=\"%6d:\" -DL_DEFAULT_PARAMS=stdout \
	-DL_SHOW_TIME_NOW=counter\(\) -I../src ../src/libnana.a

echo "*** timetrial.c - measure the time for basic operations"
echo "***    do not take these measurements too seriously"
nana-clg -I../src timetrial.c ../src/libnana.a | grep -v "^mesg"

echo "** testing L_buffer.c"
runtest L_buffer.c -I. -I../src ../src/libnana.a

echo "** testing L_times.c"
runtest L_times.c -I. -I../src ../src/libnana.a

echo "** testing calls.c"
nana-clg -I. -I../src calls.c ../src/libnana.a | check.awk

echo "* End of tests"
) | tee check.log

(
echo "* Final summary of results"
echo "** Passes"
grep "^Pass" check.log | 
  awk '{ print $0; s += $2 } END { print "Total Passes: " s }'
) | tee /tmp/$$
cat /tmp/$$ >>check.log

# Find all the failures (well some of them)
(
grep "^Fail" check.log | grep -v "^Failed 7 failures, 10 successes selftest.c"
grep "^Passed 0" check.log 
) > /tmp/$$

echo "** Failures"
echo "** Failures" >>check.log
cat /tmp/$$ 
cat /tmp/$$ >>check.log

if test -s /tmp/$$
then
  echo "**** checkall: failed ****"
  echo "**** checkall: failed ****" >>check.log
  echo "failed" > check.sum
  rm /tmp/$$
  exit 1
else
  echo "**** checkall: passed ****"
  echo "**** checkall: passed ****" >>check.log
  echo "passed" > check.sum
  rm /tmp/$$
  exit 0
fi












