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