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