1.1 --- a/test_all.sh Tue Jan 10 21:41:46 2017 +0100
1.2 +++ b/test_all.sh Tue Jan 10 23:00:46 2017 +0100
1.3 @@ -1,7 +1,29 @@
1.4 #!/bin/sh
1.5
1.6 +# This tool runs the toolchain for each of the tests, optionally building and
1.7 +# running the test programs.
1.8 +#
1.9 +# Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
1.10 +#
1.11 +# This program is free software; you can redistribute it and/or modify it under
1.12 +# the terms of the GNU General Public License as published by the Free Software
1.13 +# Foundation; either version 3 of the License, or (at your option) any later
1.14 +# version.
1.15 +#
1.16 +# This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +# details.
1.20 +#
1.21 +# You should have received a copy of the GNU General Public License along with
1.22 +# this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +
1.24 +PROGNAME=$0
1.25 +OPTION=$1
1.26 +
1.27 LPLC="./lplc"
1.28 DATADIR="_lplc"
1.29 +TESTINPUT="_results/testinput.txt"
1.30
1.31 # Expect failure from the "bad" tests.
1.32
1.33 @@ -27,19 +49,46 @@
1.34
1.35 # Main program.
1.36
1.37 -OPTION=$1
1.38 -TESTINPUT="_results/testinput.txt"
1.39 +# Show help if requested.
1.40 +
1.41 +if [ "$OPTION" = '--help' ] ; then
1.42 + cat 1>&2 <<EOF
1.43 +Usage: $0 [ --build | --build-only | --run-built ]
1.44 +
1.45 +Run the toolchain over all tests in the tests directory.
1.46
1.47 -# Make any required results directory.
1.48 +If --build is specified, the generated program code will be compiled and run,
1.49 +with the results collected in the _results directory.
1.50 +
1.51 +If --build-only is specified, the generated programs themselves will be
1.52 +collected in the _results directory, each taking their name from that of the
1.53 +main program file used as input.
1.54 +
1.55 +If --run-built is specified, any generated programs in the _results directory
1.56 +will be run and their output collected in the _results directory.
1.57
1.58 -if [ "$OPTION" = '--build' ] || [ "$OPTION" = '--build-only' ] ; then
1.59 - if [ ! -e "_results" ]; then
1.60 - mkdir "_results"
1.61 - else
1.62 - rm "_results/"*
1.63 - fi
1.64 +By using --build-only on one system, copying the _results directory to another
1.65 +system, and then running this script with the --run-built option on the other
1.66 +system, it becomes possible to test the toolchain output on the other system
1.67 +without needing to actually use the toolchain on that system. This permits the
1.68 +testing of cross-compiled programs.
1.69 +
1.70 +For example, to build on one system but not run the generated programs:
1.71 +
1.72 +ARCH=mipsel-linux-gnu $PROGNAME --build-only
1.73
1.74 - cp "tests/testinput.txt" "$TESTINPUT"
1.75 +And to run the generated programs on another system:
1.76 +
1.77 +$PROGNAME --run-built
1.78 +
1.79 +Of course, this script will need to be copied to the target system if it is not
1.80 +already available there.
1.81 +
1.82 +Build and output logs are stored in the _results directory with the .build and
1.83 +.out suffixes employed respectively, one of each kind for each generated
1.84 +program.
1.85 +EOF
1.86 + exit 1
1.87 fi
1.88
1.89 # If just running existing programs, do so now and exit.
1.90 @@ -66,6 +115,18 @@
1.91 exit 0
1.92 fi
1.93
1.94 +# Make any required results directory.
1.95 +
1.96 +if [ "$OPTION" = '--build' ] || [ "$OPTION" = '--build-only' ] ; then
1.97 + if [ ! -e "_results" ]; then
1.98 + mkdir "_results"
1.99 + else
1.100 + rm "_results/"*
1.101 + fi
1.102 +
1.103 + cp "tests/testinput.txt" "$TESTINPUT"
1.104 +fi
1.105 +
1.106 # Perform each test.
1.107
1.108 for FILENAME in tests/* ; do