libustctl: use direct socket communication
[lttng-ust.git] / tests / test_functions.sh
CommitLineData
dd7a064c
NC
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
20function starttest() {
21
22 echo "------------------------------------"
23 echo "Starting test: $1"
24 echo "------------------------------------"
25}
26
27function 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
42function trace_matches() {
d9ac3d71 43 local OPTIND=
dd7a064c 44
291d30c0
YB
45 #Get a textdump command
46 # if RUNLTTV is defined try to use it
47 # if LTTV variable is defined try to use it
48 # try to find lttv in the path
49 # try to find runlttv in std paths (devel/lttv/runlttv and ust/../lttv/runlttv
50
51 if [ ! -d "$RUNLTTV" -a -x "$RUNLTTV" ]; then
52 LTTV_TEXTDUMP_CMD="$RUNLTTV -m text "
53 LTTV_TRACE_PREFIX=""
54
55 elif [ -d "$RUNLTTV" -a -x "$RUNLTTV/runlttv" ]; then
56 LTTV_TEXTDUMP_CMD="$RUNLTTV/runlttv -m text "
57 LTTV_TRACE_PREFIX=""
58
59 elif [ ! -d "$LTTV" -a -x "$LTTV" ]; then
60 LTTV_TEXTDUMP_CMD="$LTTV -m textDump "
61 LTTV_TRACE_PREFIX="-t"
62
63 elif [ -d "$LTTV" -a -x "$LTTV/lttv" ]; then
64 LTTV_TEXTDUMP_CMD="$LTTV/lttv -m textDump "
65 LTTV_TRACE_PREFIX="-t"
66
67 elif [ -x "$(which lttv.real)" ]; then
68 LTTV_TEXTDUMP_CMD="$(which lttv.real) -m textDump ";
69 LTTV_TRACE_PREFIX="-t"
70
71 elif [ -x "~/devel/lttv/runlttv" ]; then
72 LTTV_TEXTDUMP_CMD="~/devel/lttv/runlttv -m text ";
73 LTTV_TRACE_PREFIX=""
74
75 elif [ -x "$(dirname `readlink -f $0`)/../../lttv/runlttv" ]; then
76 LTTV_TEXTDUMP_CMD="$(dirname `readlink -f $0`)/../../lttv/runlttv -m text "
77 LTTV_TRACE_PREFIX=""
78
79 else
80 echo "$0: No lttv found. Edit \$RUNLTTV to point to your lttv source directory or \$LTTV to you lttv executable." >/dev/stderr
dd7a064c 81 exit 1;
291d30c0 82
dd7a064c
NC
83 fi
84
85 while getopts ":n:N:" options; do
86 case "$options" in
87 n) expected_count=$OPTARG;;
88 N) name=$OPTARG;;
89 *) echo "Invalid option to trace_matches"
90 exit 1;;
91 esac
92 done
93 shift $(($OPTIND - 1))
94
95 pattern=$1
96 if [ -z "$pattern" ]; then
97 error "no pattern specified"
98 usage
99 exit 1
100 fi
101
102 if [ -z "$2" ]; then
103 error "no trace directory specified"
104 return 1
105 fi
106 traces=$(find "$2" -mindepth 1 -maxdepth 1 -type d)
291d30c0
YB
107 lttv_trace_cmd=$LTTV_TEXTDUMP_CMD
108 for trace in $traces; do
109 lttv_trace_cmd="$lttv_trace_cmd $LTTV_TRACE_PREFIX $trace"
110 done
111 cnt=$($lttv_trace_cmd | grep "$pattern" | wc -l)
dd7a064c
NC
112 if [ -z "$expected_count" ]; then
113 if [ "$cnt" -eq "0" ]; then
114 fail "Did not find at least one instance of $name in trace"
115 return 1
116 else
117 pass "Found at least one instance of $name in trace."
118 return 0
119 fi
120 else
121 if [ "$cnt" -ne "$expected_count" ]; then
122 fail "Found $cnt instances of $name in trace, expected $expected_count"
123 return 1
124 else
125 pass "Found $cnt instances of $name in trace."
126 return 0
127 fi
128 fi
129}
This page took 0.029918 seconds and 5 git commands to generate.