support busybox for manual trace tests
[ust.git] / tests / trace_matches
CommitLineData
1518fa0f
PMF
1#!/bin/bash
2
1518fa0f 3function error() {
a4e9613d 4 echo "$0: $@" 1>&2
1518fa0f
PMF
5}
6
7function usage() {
8 echo "Usage: $0 [ -N pattern_name ] [ -n pattern_count ] PATTERN TRACE_PARENT_DIR"
9}
10
291d30c0
YB
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
17if [ ! -d "$RUNLTTV" -a -x "$RUNLTTV" ]; then
18 LTTV_TEXTDUMP_CMD="$RUNLTTV -m text "
19 LTTV_TRACE_PREFIX=""
20
21elif [ -d "$RUNLTTV" -a -x "$RUNLTTV/runlttv" ]; then
22 LTTV_TEXTDUMP_CMD="$RUNLTTV/runlttv -m text "
23 LTTV_TRACE_PREFIX=""
24
25elif [ ! -d "$LTTV" -a -x "$LTTV" ]; then
26 LTTV_TEXTDUMP_CMD="$LTTV -m textDump "
27 LTTV_TRACE_PREFIX="-t"
28
29elif [ -d "$LTTV" -a -x "$LTTV/lttv" ]; then
30 LTTV_TEXTDUMP_CMD="$LTTV/lttv -m textDump "
31 LTTV_TRACE_PREFIX="-t"
32
33elif [ -x "$(which lttv.real)" ]; then
34 LTTV_TEXTDUMP_CMD="$(which lttv.real) -m textDump ";
35 LTTV_TRACE_PREFIX="-t"
36
37elif [ -x "~/devel/lttv/runlttv" ]; then
38 LTTV_TEXTDUMP_CMD="~/devel/lttv/runlttv -m text ";
39 LTTV_TRACE_PREFIX=""
40
41elif [ -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
45else
a4e9613d 46 echo "$0: No lttv found. Edit \$RUNLTTV to point to your lttv source directory or \$LTTV to you lttv executable." 1>&2
1518fa0f 47 exit 1;
291d30c0 48
1518fa0f
PMF
49fi
50
51while 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
62done
63shift $(($OPTIND - 1))
64
65pattern=$1
66if [ -z "$pattern" ]; then
67 error "no pattern specified"
68 usage
69 exit 1
70fi
71
72if [ -z "$2" ]; then
73 error "no trace directory specified"
74 usage
75 exit 1
76fi
77traces=$(find "$2" -mindepth 1 -maxdepth 1 -type d)
291d30c0
YB
78lttv_trace_cmd=$LTTV_TEXTDUMP_CMD
79for trace in $traces; do
80 lttv_trace_cmd="$lttv_trace_cmd $LTTV_TRACE_PREFIX $trace"
81done
1518fa0f
PMF
82echo -n "Analyzing trace ($name): "
83
291d30c0 84cnt=$($lttv_trace_cmd | grep "$pattern" | wc -l)
1518fa0f
PMF
85if [ -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)"
4bb5ec9b 89 exit 1
1518fa0f
PMF
90 else
91 echo "Success"
92 exit 0
93 fi
94else
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
104fi
This page took 0.033538 seconds and 4 git commands to generate.