1#!/bin/bash
2#
3# Script to run a scenario file.  A scenario file contains encoder parameters
4# as well as a list of headers in QIF format.  The headers are encoded and
5# the output is then decoded and compared to the original.
6
7set -x
8set -e
9
10for NEED in interop-encode interop-decode sort-qif.pl; do
11    type $NEED
12    if [ $? -ne 0 ]; then
13        echo $NEED is not in $PATH 1>&2
14        exit 1
15    fi
16done
17
18function cleanup {
19    rm -vf $QIF_FILE
20    rm -vf $BIN_FILE
21    rm -vf $RESULTING_QIF_FILE
22    rm -vf $ENCODE_LOG
23    rmdir $DIR
24}
25
26if [ -z "$DO_CLEANUP" -o "$DO_CLEANUP" != 0 ]; then
27    trap cleanup EXIT
28fi
29
30RECIPE=$1
31
32source $RECIPE
33
34DIR=/tmp/recipe-out-$$$RANDOM
35ENCODE_LOG=$DIR/encode.log
36QIF_FILE=$DIR/qif
37BIN_FILE=$DIR/out
38RESULTING_QIF_FILE=$DIR/qif-result
39mkdir -p $DIR
40
41if [ "$AGGRESSIVE" = 1 ]; then
42    ENCODE_ARGS="$ENCODE_ARGS -A"
43fi
44
45if [ "$IMMEDIATE_ACK" = 1 ]; then
46    ENCODE_ARGS="$ENCODE_ARGS -a 1"
47fi
48
49if [ "$ANNOTATIONS" = 1 ]; then
50    ENCODE_ARGS="$ENCODE_ARGS -n"
51fi
52
53if [ -n "$RISKED_STREAMS" ]; then
54    ENCODE_ARGS="$ENCODE_ARGS -s $RISKED_STREAMS"
55    DECODE_ARGS="$DECODE_ARGS -s $RISKED_STREAMS"
56fi
57
58if [ -n "$TABLE_SIZE" ]; then
59    ENCODE_ARGS="$ENCODE_ARGS -t $TABLE_SIZE"
60    DECODE_ARGS="$DECODE_ARGS -t $TABLE_SIZE"
61fi
62
63echo -e "$QIF"\\n > $QIF_FILE
64
65interop-encode $ENCODE_ARGS -i $QIF_FILE -o $BIN_FILE 2>$ENCODE_LOG
66interop-decode $DECODE_ARGS -i $BIN_FILE -o $RESULTING_QIF_FILE
67diff <(sort-qif.pl --strip $QIF_FILE) \
68                <(sort-qif.pl --strip $RESULTING_QIF_FILE)
69