xref: /netbsd-src/external/lgpl3/gmp/dist/mini-gmp/tests/run-tests (revision 212397c69a103ae7e5eafa8731ddfae671d2dee7)
1#! /bin/sh
2
3# Copyright (C) 2000, 2001, 2002, 2004, 2005, 2011, 2012  Niels Möller
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19failed=0
20all=0
21
22debug='no'
23testflags=''
24
25if [ -z "$srcdir" ] ; then
26  srcdir=`pwd`
27fi
28
29export srcdir
30
31# When used in make rules, we sometimes get the filenames VPATH
32# expanded, but usually not.
33find_program () {
34    case "$1" in
35	*/*)
36	  echo "$1"
37	  ;;
38	*)
39	  if [ -x "$1" ] ; then
40	      echo "./$1"
41	  else
42	      echo "$srcdir/$1"
43	  fi
44	  ;;
45    esac
46}
47
48env_program () {
49  if [ -x "$1" ] ; then
50    if "$1"; then : ; else
51      echo FAIL: $1
52      exit 1
53    fi
54  fi
55}
56
57test_program () {
58  testname=`basename "$1" .exe`
59  testname=`basename "$testname" -test`
60  if [ -z "$EMULATOR" ] || head -1 "$1" | grep '^#!' > /dev/null; then
61    "$1" $testflags
62  else
63    $EMULATOR "$1" $testflags
64  fi
65  case "$?" in
66      0)
67	echo PASS: $testname
68	all=`expr $all + 1`
69	;;
70      77)
71	echo SKIP: $testname
72      ;;
73      *)
74	echo FAIL: $testname
75	failed=`expr $failed + 1`
76	all=`expr $all + 1`
77	;;
78  esac
79}
80
81env_program `find_program setup-env`
82
83while test $# != 0
84do
85  case "$1" in
86  --debug)
87    debug=yes
88    ;;
89  -v)
90    testflags='-v'
91    ;;
92  -*)
93    echo >&2 'Unknown option `'"$1'"
94    exit 1
95    ;;
96  *)
97    break
98    ;;
99  esac
100  shift
101done
102
103if [ $# -eq 0 ] ; then
104  for f in *-test; do test_program "./$f"; done
105else
106  for f in "$@" ; do test_program `find_program "$f"`; done
107fi
108
109if [ $failed -eq 0 ] ; then
110  banner="All $all tests passed"
111else
112  banner="$failed of $all tests failed"
113fi
114dashes=`echo "$banner" | sed s/./=/g`
115echo "$dashes"
116echo "$banner"
117echo "$dashes"
118
119if [ "x$debug" = xno ] ; then
120  env_program `find_program teardown-env`
121fi
122
123[ "$failed" -eq 0 ]
124