summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/tests/run_test
blob: 12458e343fa8c90f0a3bf33e8bb1818dfb2a5235 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
# 
#   http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

#
# Set up environment and run a test executable or script.
#
# Output nothing if test passes, show the output if it fails and
# leave output in <test>.log for examination.  
#
# If qpidd.port exists and is not empty run test with QPID_PORT=`cat qpidd.port`
# 
# If $VALGRIND if is set run under valgrind. If there are valgrind
# erros show valgrind output, also leave it in <test>.valgrind for
# examination.
#

working_dir='.'

OPTS=$(getopt -n "Qpid Test Wrapper" -o d:b:s:p -l working-dir:,build-dir:,source-dir:,python,start-broker,broker-options: -- "$@") || exit 1
eval set -- $OPTS

while true; do
case "$1" in
    -d|--working-dir) working_dir=$2;    shift 2      ;;
    -b|--build-dir)   build_dir=$2;      shift 2      ;;
    -s|--source-dir)  source_dir=$2;     shift 2      ;;
    -p|--python)      run_python=yes;    shift        ;;
    --start-broker)   start_broker=yes;  shift        ;;
    --broker-options) qpidd_extra_options=$2; shift 2 ;;
    --)                                  shift; break ;;
esac
done

program=$1
shift

logfilebase=$(pwd -P)/$(basename $program)
source $build_dir/src/tests/test_env.sh || (echo "Error: Couldn't read test_env.sh (build settings)" ; exit 1)
source $srcdir/vg_check


# Use VALGRIND_OPTS="--gen-suppressions=all" to generated suppressions
VALGRIND_OPTS="$VALGRIND_OPTS
--leak-check=full
--demangle=yes
--suppressions=$srcdir/.valgrind.supp
--num-callers=25
"

# Set up environment for running a Qpid test
if [ -n "$start_broker" ] ; then
  qpidd_options="--auth=no --no-module-dir --daemon --port=0 --interface 127.0.0.1 --log-to-file $logfilebase-qpidd.log $qpidd_extra_options"
  if [ -n "$VALGRIND" ] ; then
    QPID_PORT=$($VALGRIND $VALGRIND_OPTS --log-file=$logfilebase-qpidd.vglog -- $QPIDD_EXEC $qpidd_options)
  else
    QPID_PORT=$($QPID_EXEC $qpidd_options)
  fi
elif [ -r qpidd.port ]; then
  QPID_PORT=$(cat qpidd.port)
fi
export QPID_PORT
QPID_LOG_TO_FILE="$logfilebase.log"
export QPID_LOG_TO_FILE

# Export variables from makefile.
export srcdir

VG_LOG="$logfilebase.vglog"
rm -f $VG_LOG*

ERROR=0
if [ -n "$run_python" -a -n "$PYTHON" ] ; then
    (cd $working_dir; $PYTHON $program "$@") || ERROR=1
elif [ ! -x $program ] ; then
    echo "Cannot execute $program"
    ERROR=1
elif (file $program | grep -q ELF) && [ -n "$VALGRIND" ] ; then
    # This is a real executable, valgrind it.
    # Hide output unless there's an error.
    (cd $working_dir; $VALGRIND $VALGRIND_OPTS --log-file=$VG_LOG -- $program "$@" 2>&1) || ERROR=1
    vg_check $VG_LOG* || ERROR=1
else
    (cd $working_dir; $program "$@") || ERROR=1
fi

# Check log
if [ -r $QPID_LOG_TO_FILE ]; then
egrep 'warning\|error\|critical' $QPID_LOG_TO_FILE && {
    echo "WARNING: Suspicious broker log entries in $QPID_LOG_TO_FILE, above."
}
fi

if [ -n "$start_broker" ] ; then
  $QPIDD_EXEC --no-module-dir --quit || ERROR=1

  # Check qpidd.log.
  egrep 'warning\|error\|critical' $logfilebase-qpidd.log && {
    echo "WARNING: Suspicious broker log entries in qpidd.log, above."
  }

  # Check valgrind log.
  if test -n "$VALGRIND"; then
    vg_check $logfilebase-qpidd.vglog || ERROR=1
  fi
fi
exit $ERROR