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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
export DEST="127.0.0.1"
ts_log()
{
echo "$@"
}
ts_err()
{
ts_log "$@" | tee >> $ERRF
}
ts_cat()
{
cat "$@"
}
ts_err_cat()
{
ts_cat "$@" | tee >> $ERRF
}
ts_skip()
{
exit 127
}
__ts_cmd()
{
CMD=$1; shift
SCRIPT=$1; shift
DESC=$1; shift
$CMD $@ 2> $STD_ERR > $STD_OUT
if [ -s $STD_ERR ]; then
ts_err "${SCRIPT}: ${DESC} failed:"
ts_err "command: $CMD $@"
ts_err "stderr output:"
ts_err_cat $STD_ERR
if [ -s $STD_OUT ]; then
ts_err "stdout output:"
ts_err_cat $STD_OUT
fi
elif [ -s $STD_OUT ]; then
echo "${SCRIPT}: ${DESC} succeeded with output:"
cat $STD_OUT
else
echo "${SCRIPT}: ${DESC} succeeded"
fi
}
ts_tc()
{
__ts_cmd "$TC" "$@"
}
ts_ip()
{
__ts_cmd "$IP" "$@"
}
ts_ss()
{
__ts_cmd "$SS" "$@"
}
ts_bridge()
{
__ts_cmd "$BRIDGE" "$@"
}
ts_qdisc_available()
{
HELPOUT=`$TC qdisc add $1 help 2>&1`
if [ "`echo $HELPOUT | grep \"^Unknown qdisc\"`" ]; then
return 0;
else
return 1;
fi
}
rand_dev()
{
rnd=""
while [ ${#rnd} -ne 6 ]; do
rnd="$(head -c 250 /dev/urandom | tr -dc '[:alpha:]' | head -c 6)"
done
echo "dev-$rnd"
}
pr_failed()
{
echo " [FAILED]"
ts_err "matching failed"
}
pr_success()
{
echo " [SUCCESS]"
}
test_on()
{
echo -n "test on: \"$1\""
if cat "$STD_OUT" | grep -qE "$1"
then
pr_success
else
pr_failed
fi
}
test_on_not()
{
echo -n "test on: \"$1\""
if cat "$STD_OUT" | grep -vqE "$1"
then
pr_success
else
pr_failed
fi
}
test_lines_count()
{
echo -n "test on lines count ($1): "
if [ $(cat "$STD_OUT" | wc -l) -eq "$1" ]
then
pr_success
else
pr_failed
fi
}
|