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