support busybox for manual trace tests
[ust.git] / tests / trace_matches
1 #!/bin/bash
2
3 function error() {
4 echo "$0: $@" 1>&2
5 }
6
7 function usage() {
8 echo "Usage: $0 [ -N pattern_name ] [ -n pattern_count ] PATTERN TRACE_PARENT_DIR"
9 }
10
11 #Get a textdump command
12 # if RUNLTTV is defined try to use it
13 # if LTTV variable is defined try to use it
14 # try to find lttv in the path
15 # try to find runlttv in std paths (devel/lttv/runlttv and ust/../lttv/runlttv
16
17 if [ ! -d "$RUNLTTV" -a -x "$RUNLTTV" ]; then
18 LTTV_TEXTDUMP_CMD="$RUNLTTV -m text "
19 LTTV_TRACE_PREFIX=""
20
21 elif [ -d "$RUNLTTV" -a -x "$RUNLTTV/runlttv" ]; then
22 LTTV_TEXTDUMP_CMD="$RUNLTTV/runlttv -m text "
23 LTTV_TRACE_PREFIX=""
24
25 elif [ ! -d "$LTTV" -a -x "$LTTV" ]; then
26 LTTV_TEXTDUMP_CMD="$LTTV -m textDump "
27 LTTV_TRACE_PREFIX="-t"
28
29 elif [ -d "$LTTV" -a -x "$LTTV/lttv" ]; then
30 LTTV_TEXTDUMP_CMD="$LTTV/lttv -m textDump "
31 LTTV_TRACE_PREFIX="-t"
32
33 elif [ -x "$(which lttv.real)" ]; then
34 LTTV_TEXTDUMP_CMD="$(which lttv.real) -m textDump ";
35 LTTV_TRACE_PREFIX="-t"
36
37 elif [ -x "~/devel/lttv/runlttv" ]; then
38 LTTV_TEXTDUMP_CMD="~/devel/lttv/runlttv -m text ";
39 LTTV_TRACE_PREFIX=""
40
41 elif [ -x "$(dirname `readlink -f $0`)/../../lttv/runlttv" ]; then
42 LTTV_TEXTDUMP_CMD="$(dirname `readlink -f $0`)/../../lttv/runlttv -m text "
43 LTTV_TRACE_PREFIX=""
44
45 else
46 echo "$0: No lttv found. Edit \$RUNLTTV to point to your lttv source directory or \$LTTV to you lttv executable." 1>&2
47 exit 1;
48
49 fi
50
51 while getopts ":n:N:" options; do
52 case "$options" in
53 n) expected_count=$OPTARG;;
54 N) name=$OPTARG;;
55 h) usage;
56 exit 0;;
57 \?) usage
58 exit 1;;
59 *) usage
60 exit 1;;
61 esac
62 done
63 shift $(($OPTIND - 1))
64
65 pattern=$1
66 if [ -z "$pattern" ]; then
67 error "no pattern specified"
68 usage
69 exit 1
70 fi
71
72 if [ -z "$2" ]; then
73 error "no trace directory specified"
74 usage
75 exit 1
76 fi
77 traces=$(find "$2" -mindepth 1 -maxdepth 1 -type d)
78 lttv_trace_cmd=$LTTV_TEXTDUMP_CMD
79 for trace in $traces; do
80 lttv_trace_cmd="$lttv_trace_cmd $LTTV_TRACE_PREFIX $trace"
81 done
82 echo -n "Analyzing trace ($name): "
83
84 cnt=$($lttv_trace_cmd | grep "$pattern" | wc -l)
85 if [ -z "$expected_count" ]; then
86 if [ "$cnt" -eq "0" ]; then
87 echo "ERROR"
88 echo "Did not find at least one instance of this event ($cnt)"
89 exit 1
90 else
91 echo "Success"
92 exit 0
93 fi
94 else
95 if [ "$cnt" -ne "$expected_count" ]; then
96 echo "ERROR"
97 echo "Expected: $expected_count"
98 echo "In trace: $cnt"
99 exit 1
100 else
101 echo "Success"
102 exit 0
103 fi
104 fi
This page took 0.030705 seconds and 4 git commands to generate.