| 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 | exit 1 |
| 54 | else |
| 55 | echo "Success" |
| 56 | exit 0 |
| 57 | fi |
| 58 | else |
| 59 | if [ "$cnt" -ne "$expected_count" ]; then |
| 60 | echo "ERROR" |
| 61 | echo "Expected: $expected_count" |
| 62 | echo "In trace: $cnt" |
| 63 | exit 1 |
| 64 | else |
| 65 | echo "Success" |
| 66 | exit 0 |
| 67 | fi |
| 68 | fi |