blob: bfd1cf2a2333232ac010046ed6fd9605643a4b8c [file] [log] [blame]
kate.ward2f3cad92008-10-21 23:29:23 +00001#! /bin/sh
kate.ward2f3cad92008-10-21 23:29:23 +00002# vim:et:ft=sh:sts=2:sw=2
3#
kate.ward2f3cad92008-10-21 23:29:23 +00004# This script runs the provided unit tests and sends the output to the
5# appropriate file.
kate.ward2f3cad92008-10-21 23:29:23 +00006
Kate Warda397c1c2016-01-10 19:40:24 +01007# Treat unset variables as an error.
kate.ward2f3cad92008-10-21 23:29:23 +00008set -u
9
Kate Warda397c1c2016-01-10 19:40:24 +010010die() {
kate.ward2f3cad92008-10-21 23:29:23 +000011 [ $# -gt 0 ] && echo "error: $@" >&2
12 exit 1
13}
14
kate.ward2f3cad92008-10-21 23:29:23 +000015BASE_DIR="`dirname $0`/.."
kate.ward2f3cad92008-10-21 23:29:23 +000016LIB_DIR="${BASE_DIR}/lib"
kate.ward2f3cad92008-10-21 23:29:23 +000017
Kate Warda397c1c2016-01-10 19:40:24 +010018# Load libraries.
kate.warde7ed70c2011-06-10 11:45:17 +000019. ${LIB_DIR}/shflags || die 'unable to load shflags library'
20. ${LIB_DIR}/shlib || die 'unable to load shlib library'
kate.ward2f3cad92008-10-21 23:29:23 +000021. ${LIB_DIR}/versions || die 'unable to load versions library'
22
Kate Warda397c1c2016-01-10 19:40:24 +010023# Redefining BASE_DIR now that we have the shlib functions.
kate.warde7ed70c2011-06-10 11:45:17 +000024BASE_DIR=`shlib_relToAbsPath "${BASE_DIR}"`
25BIN_DIR="${BASE_DIR}/bin"
26SRC_DIR="${BASE_DIR}/src"
kate.ward2f3cad92008-10-21 23:29:23 +000027
kate.warde7ed70c2011-06-10 11:45:17 +000028os_name=`versions_osName |sed 's/ /_/g'`
29os_version=`versions_osVersion`
30
Kate Warda397c1c2016-01-10 19:40:24 +010031# Load external flags.
kate.warde7ed70c2011-06-10 11:45:17 +000032. ${BIN_DIR}/gen_test_results.flags
33
Kate Warda397c1c2016-01-10 19:40:24 +010034# Define flags.
kate.ward2f3cad92008-10-21 23:29:23 +000035DEFINE_boolean force false 'force overwrite' f
36DEFINE_string output_dir "`pwd`" 'output dir' d
kate.warde7ed70c2011-06-10 11:45:17 +000037DEFINE_string output_file "${os_name}-${os_version}.txt" 'output file' o
kate.ward4a16b432013-01-05 12:29:36 +000038DEFINE_boolean dry_run false "supress logging to a file" n
kate.ward2f3cad92008-10-21 23:29:23 +000039
Kate Warda397c1c2016-01-10 19:40:24 +010040main() {
41 # Determine output filename.
kate.wardaf8d27d2013-01-16 22:35:45 +000042 output="${FLAGS_output_dir:+${FLAGS_output_dir}/}${FLAGS_output_file}"
43 output=`shlib_relToAbsPath "${output}"`
Kate Warda397c1c2016-01-10 19:40:24 +010044
45 # Checks.
kate.wardaf8d27d2013-01-16 22:35:45 +000046 [ -n "${FLAGS_suite:-}" ] || die 'suite flag missing'
Kate Warda397c1c2016-01-10 19:40:24 +010047
kate.wardaf8d27d2013-01-16 22:35:45 +000048 if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} -a -f "${output}" ]; then
49 if [ ${FLAGS_force} -eq ${FLAGS_TRUE} ]; then
50 rm -f "${output}"
51 else
52 echo "not overwriting '${output}'" >&2
53 exit ${FLAGS_ERROR}
54 fi
kate.ward2f3cad92008-10-21 23:29:23 +000055 fi
kate.wardf4997502013-01-05 14:11:44 +000056 if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then
kate.wardaf8d27d2013-01-16 22:35:45 +000057 touch "${output}" 2>/dev/null || die "unable to write to '${output}'"
kate.ward4a16b432013-01-05 12:29:36 +000058 fi
Kate Warda397c1c2016-01-10 19:40:24 +010059
60 # Run tests.
kate.wardaf8d27d2013-01-16 22:35:45 +000061 (
62 cd "${SRC_DIR}";
63 if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then
64 ./${FLAGS_suite} |tee "${output}"
65 else
66 ./${FLAGS_suite}
67 fi
68 )
Kate Warda397c1c2016-01-10 19:40:24 +010069
kate.wardaf8d27d2013-01-16 22:35:45 +000070 if [ ! ${FLAGS_dry_run} ]; then
71 echo >&2
72 echo "output written to '${output}'" >&2
73 fi
74}
kate.ward2f3cad92008-10-21 23:29:23 +000075
kate.wardaf8d27d2013-01-16 22:35:45 +000076FLAGS "$@" || exit $?
77[ ${FLAGS_help} -eq ${FALSE} ] || exit
78eval set -- "${FLAGS_ARGV}"
79main "$@"