#! /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.5 1998/07/03 03:25:32 pjm Exp $

(
PATH=../src:.:${PATH}

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"
    sh ../src/nana-clg -L../src -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 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"
    sh ../src/nana-c++lg -L../src -I../src -I. -DEIFFEL_CHECK=CHECK_ALL $cflags $file | 
      check.awk $file "g++ $cflags"
  done
done

echo "* manyDL.c - bash testing for many (1024) DL messages"
cnt=`nana-clg manyDL.c -I. -I../src -L../src | 
     grep "the rain in spain" | wc -l` 
if [$cnt != 1024 ]
then 
  echo "error: manyDL.c $cnt != 1024"
  echo "Failed: 1 failure, 0 successes"
else
  echo "Passed 1024 tests completed successfully"
fi

echo "* manyDI.c - bash testing for many (1024) DI checks"
nana-clg -L../src -I../src -I. -I../src ../src/libnana.a manyDI.c | ./check.awk

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

# I've removed some of the older tests pending a rewrite
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












