Changes testcases in runtests to use TAP
[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
44 RUNLTTV=~/devel/lttv/runlttv
45
46 if [ ! -x "$RUNLTTV" ]; then
47 echo "$0: $RUNLTTV not executable. Edit \$RUNLTTV to point to your lttv source directory." >/dev/stderr
48 exit 1;
49 fi
50
51 while getopts ":n:N:" options; do
52 case "$options" in
53 n) expected_count=$OPTARG;;
54 N) name=$OPTARG;;
55 *) echo "Invalid option to trace_matches"
56 exit 1;;
57 esac
58 done
59 shift $(($OPTIND - 1))
60
61 pattern=$1
62 if [ -z "$pattern" ]; then
63 error "no pattern specified"
64 usage
65 exit 1
66 fi
67
68 if [ -z "$2" ]; then
69 error "no trace directory specified"
70 return 1
71 fi
72 traces=$(find "$2" -mindepth 1 -maxdepth 1 -type d)
73
74 cnt=$($RUNLTTV -m text "$traces" | grep "$pattern" | wc -l)
75 if [ -z "$expected_count" ]; then
76 if [ "$cnt" -eq "0" ]; then
77 fail "Did not find at least one instance of $name in trace"
78 return 1
79 else
80 pass "Found at least one instance of $name in trace."
81 return 0
82 fi
83 else
84 if [ "$cnt" -ne "$expected_count" ]; then
85 fail "Found $cnt instances of $name in trace, expected $expected_count"
86 return 1
87 else
88 pass "Found $cnt instances of $name in trace."
89 return 0
90 fi
91 fi
92 }
This page took 0.030171 seconds and 4 git commands to generate.