tests: add testsuite scripts
[ust.git] / tests / trace_matches
1 #!/bin/bash
2
3 RUNLTTV=~/devel/lttv/runlttv
4
5 function error() {
6 echo "$0: $@" >/dev/stderr
7 }
8
9 function usage() {
10 echo "Usage: $0 [ -N pattern_name ] [ -n pattern_count ] PATTERN TRACE_PARENT_DIR"
11 }
12
13 if [ ! -x "$RUNLTTV" ]; then
14 echo "$0: $RUNLTTV not executable. Edit \$RUNLTTV to point to your lttv source directory." >/dev/stderr
15 exit 1;
16 fi
17
18 while getopts ":n:N:" options; do
19 case "$options" in
20 n) expected_count=$OPTARG;;
21 N) name=$OPTARG;;
22 h) usage;
23 exit 0;;
24 \?) usage
25 exit 1;;
26 *) usage
27 exit 1;;
28 esac
29 done
30 shift $(($OPTIND - 1))
31
32 pattern=$1
33 if [ -z "$pattern" ]; then
34 error "no pattern specified"
35 usage
36 exit 1
37 fi
38
39 if [ -z "$2" ]; then
40 error "no trace directory specified"
41 usage
42 exit 1
43 fi
44 traces=$(find "$2" -mindepth 1 -maxdepth 1 -type d)
45
46 echo -n "Analyzing trace ($name): "
47
48 cnt=$($RUNLTTV -m text "$traces" | grep "$pattern" | wc -l)
49 if [ -z "$expected_count" ]; then
50 if [ "$cnt" -eq "0" ]; then
51 echo "ERROR"
52 echo "Did not find at least one instance of this event ($cnt)"
53 else
54 echo "Success"
55 exit 0
56 fi
57 else
58 if [ "$cnt" -ne "$expected_count" ]; then
59 echo "ERROR"
60 echo "Expected: $expected_count"
61 echo "In trace: $cnt"
62 exit 1
63 else
64 echo "Success"
65 exit 0
66 fi
67 fi
This page took 0.031572 seconds and 5 git commands to generate.