qse/qse/regress/sed/regress.sh.in

192 lines
4.5 KiB
Bash
Raw Normal View History

2009-09-09 01:05:48 +00:00
#!/bin/sh
echo_so()
{
tput smso
while [ $# -gt 0 ]
do
echo -n "$1 "
shift
done
echo
tput rmso
}
echo_title()
{
echo "--------------------------------------------------------------------------------"
while [ $# -gt 0 ]
do
2010-08-01 01:45:47 +00:00
echo -n "[CMD] $1 "
echo -n "[CMD] $1 " >/dev/stderr
2009-09-09 01:05:48 +00:00
shift
done
echo
echo > /dev/stderr
echo "--------------------------------------------------------------------------------"
}
print_usage()
{
echo_so "Usage: $0 init"
echo_so " $0 test"
}
###################
# MAIN #
###################
[ -z "${QSESED}" ] && {
QSESED="@abs_top_builddir@/cmd/sed/.libs/qsesed"
[ -f "${QSESED}" ] || QSESED="@abs_top_builddir@/cmd/sed/qsesed"
2009-09-09 01:05:48 +00:00
}
[ -f "${QSESED}" -a -x "${QSESED}" ] || {
echo_so "the executable '${QSESED}' is not found or not executable"
exit 1
}
QSESED_BASENAME="`basename "${QSESED}"`"
BASE_OUTFILE="@abs_top_srcdir@/regress/sed/regress.out"
BASE_OUTFILE_XMA="@abs_top_srcdir@/regress/sed/regress.out.xma"
2009-09-09 01:05:48 +00:00
TMPFILE="${TMPFILE:=./regress.temp}"
OUTFILE="${OUTFILE:=./regress.out}"
2010-08-01 01:45:47 +00:00
OUTFILE_XMA="${OUTFILE}.xma"
XMAOPTS="-m 500000"
2010-07-29 07:27:03 +00:00
2009-09-09 01:05:48 +00:00
PROGS="
s001.sed/s001.dat//-n -r
s002.sed/s002.dat//
s003.sed/s003.dat//
s004.sed/s004.dat//
s005.sed/s005.dat//
s006.sed/s006.dat//
s007.sed/s007.dat//
s008.sed/s008.dat//-w
2009-09-09 01:05:48 +00:00
"
[ -x "${QSESED}" ] ||
{
echo "ERROR: ${QSESED} not found"
exit 1;
}
run_scripts()
{
2009-09-09 01:39:46 +00:00
valgrind="$1"
2010-08-01 01:45:47 +00:00
extraopts="$2"
2009-09-09 01:05:48 +00:00
echo "${PROGS}" > "${TMPFILE}"
while read prog
do
[ -z "${prog}" ] && continue
2009-09-09 01:39:46 +00:00
script="`echo ${prog} | cut -d/ -f1`"
datafile="`echo ${prog} | cut -d/ -f2`"
readinfile="`echo ${prog} | cut -d/ -f3`"
2009-09-09 01:39:46 +00:00
options="`echo ${prog} | cut -d/ -f4`"
2009-09-09 01:05:48 +00:00
[ -z "${script}" ] && continue
script_path="@abs_srcdir@/${script}"
datafile_path="@abs_srcdir@/${datafile}"
readinfile_path="@abs_srcdir@/${readinfile}"
[ -f "${script_path}" ] ||
2009-09-09 01:05:48 +00:00
{
echo_so "${script_path} not found"
2009-09-09 01:05:48 +00:00
continue
}
[ -z "${readinfile}" ] &&
{
readinfile="/dev/stdin"
readinfile_path="/dev/stdin"
}
# if the datafile does not exist, let's not use the original name
#[ -f "${datafile_path}" ] || datafile_path="$datafile"
2009-09-09 01:05:48 +00:00
echo_title "${valgrind} ${QSESED_BASENAME} ${extraopts} ${options} -f ${script} ${datafile} <${readinfile} 2>&1"
${valgrind} ${QSESED} ${extraopts} ${options} -f ${script_path} ${datafile_path} <${readinfile_path} 2>&1
2009-09-09 01:05:48 +00:00
done < "${TMPFILE}"
rm -f "${TMPFILE}"
}
2010-08-01 01:45:47 +00:00
run_test()
{
base_outfile="${1}"
outfile="${2}"
extraopts="${3}"
2010-08-01 01:45:47 +00:00
run_scripts "" "${extraopts}"> "${outfile}.test"
# diff -q is not supported on old platforms.
# redirect output to /dev/null instead.
diff "${base_outfile}" "${outfile}.test" > /dev/null || {
2010-08-01 01:45:47 +00:00
echo_so "ERROR: Difference is found between expected output and actual output."
echo_so " The expected output is stored in '${base_outfile}'."
2010-08-01 01:45:47 +00:00
echo_so " The actual output is stored in '${outfile}.test'."
echo_so " You may execute 'diff ${base_outfile} ${outfile}.test' for more info."
2010-08-01 01:45:47 +00:00
return 1
}
# rm -f "${outfile}.test"
2010-08-01 01:45:47 +00:00
return 0
}
2009-09-09 01:05:48 +00:00
case $1 in
init)
run_scripts "" "" > "${BASE_OUTFILE}"
run_scripts "" "${XMAOPTS}" > "${BASE_OUTFILE_XMA}"
2009-09-09 01:05:48 +00:00
echo_so "INIT OK"
;;
test)
run_test "${BASE_OUTFILE}" "${OUTFILE}" "" &&
{
run_test "${BASE_OUTFILE_XMA}" "${OUTFILE_XMA}" "${XMAOPTS}" &&
{
${QSESED} "s|${QSESED_BASENAME} ${XMAOPTS}|${QSESED_BASENAME} |" "${OUTFILE_XMA}.test" > "${OUTFILE_XMA}.$$"
diff "${OUTFILE}.test" "${OUTFILE_XMA}.$$" ||
{
2010-08-01 01:45:47 +00:00
rm -f "${OUTFILE_XMA}.$$"
echo_so "ERROR: Difference is found between normal output and xma output."
echo_so " The normal output is stored in '${OUTFILE}.test'."
echo_so " The xma output is stored in '${OUTFILE_XMA}.test'."
2010-08-01 01:45:47 +00:00
echo_so " Ignore lines staring with [CMD] in the difference."
exit 1;
}
rm -f "${OUTFILE_XMA}.$$"
echo_so "TEST OK"
}
2009-09-09 01:05:48 +00:00
}
;;
leakcheck)
2009-09-09 01:39:46 +00:00
bin_valgrind="`which valgrind 2> /dev/null || echo ""`"
[ -n "${bin_valgrind}" -a -f "${bin_valgrind}" ] || {
2009-09-09 01:05:48 +00:00
echo_so "valgrind not found. cannot perform this test"
exit 1
}
2009-09-09 01:39:46 +00:00
run_scripts "${bin_valgrind} --leak-check=full --show-reachable=yes --track-fds=yes" 2>&1 > "${OUTFILE}.test"
x=`grep -Fic "no leaks are possible" "${OUTFILE}.test"`
y=`grep -Fic "${bin_valgrind}" "${OUTFILE}.test"`
if [ ${x} -eq ${y} ]
then
echo_so "(POSSIBLY) no memory leaks detected".
else
echo_so "(POSSIBLY) some memory leaks detected".
fi
echo_so "Inspect the '${OUTFILE}.test' file for details"
2009-09-09 01:05:48 +00:00
;;
*)
echo_so "USAGE: $0 init"
echo_so " $0 test"
echo_so " $0 leakcheck"
exit 1
;;
esac
exit 0