test_functions.sh: don't override RUNLTTV
[lttng-ust.git] / tests / test_functions.sh
1 #!/bin/bash
2 #
3 # Copyright 2010 Ericsson AB
4 #
5 # This file is part of LTTng-UST.
6 #
7 # LTTng-UST is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # LTTng-UST is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with LTTng-UST. If not, see <http://www.gnu.org/licenses/>.
19
20 function starttest() {
21
22 echo "------------------------------------"
23 echo "Starting test: $1"
24 echo "------------------------------------"
25 }
26
27 function check_trace_logs() {
28 TRACE=$1
29
30 for f in $(ls $1/*.log); do
31 NLINES=$(egrep "Warning|Error" $f | wc -l)
32 if [ "$NLINES" -ne "0" ]; then
33 fail "Errors/warnings found in $f"
34 return 1;
35 fi
36 done
37 pass "$f was consistent"
38 return 0;
39 }
40
41
42 function trace_matches() {
43 local OPTIND=
44
45 if [ ! -x "$RUNLTTV" ]; then
46 echo "$0: $RUNLTTV not executable. Edit \$RUNLTTV to point to your lttv source directory." >/dev/stderr
47 exit 1;
48 fi
49
50 while getopts ":n:N:" options; do
51 case "$options" in
52 n) expected_count=$OPTARG;;
53 N) name=$OPTARG;;
54 *) echo "Invalid option to trace_matches"
55 exit 1;;
56 esac
57 done
58 shift $(($OPTIND - 1))
59
60 pattern=$1
61 if [ -z "$pattern" ]; then
62 error "no pattern specified"
63 usage
64 exit 1
65 fi
66
67 if [ -z "$2" ]; then
68 error "no trace directory specified"
69 return 1
70 fi
71 traces=$(find "$2" -mindepth 1 -maxdepth 1 -type d)
72
73 cnt=$($RUNLTTV -m text "$traces" | grep "$pattern" | wc -l)
74 if [ -z "$expected_count" ]; then
75 if [ "$cnt" -eq "0" ]; then
76 fail "Did not find at least one instance of $name in trace"
77 return 1
78 else
79 pass "Found at least one instance of $name in trace."
80 return 0
81 fi
82 else
83 if [ "$cnt" -ne "$expected_count" ]; then
84 fail "Found $cnt instances of $name in trace, expected $expected_count"
85 return 1
86 else
87 pass "Found $cnt instances of $name in trace."
88 return 0
89 fi
90 fi
91 }
This page took 0.034109 seconds and 4 git commands to generate.