• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2export DEST="127.0.0.1"
3
4ts_log()
5{
6	echo "$@"
7}
8
9ts_err()
10{
11	ts_log "$@" | tee >> $ERRF
12}
13
14ts_cat()
15{
16	cat "$@"
17}
18
19ts_err_cat()
20{
21	ts_cat "$@" | tee >> $ERRF
22}
23
24ts_skip()
25{
26    exit 127
27}
28
29ts_tc()
30{
31	SCRIPT=$1; shift
32	DESC=$1; shift
33
34	$TC $@ 2> $STD_ERR > $STD_OUT
35
36	if [ -s $STD_ERR ]; then
37		ts_err "${SCRIPT}: ${DESC} failed:"
38		ts_err "command: $TC $@"
39		ts_err "stderr output:"
40		ts_err_cat $STD_ERR
41		if [ -s $STD_OUT ]; then
42			ts_err "stdout output:"
43			ts_err_cat $STD_OUT
44		fi
45	elif [ -s $STD_OUT ]; then
46		echo "${SCRIPT}: ${DESC} succeeded with output:"
47		cat $STD_OUT
48	else
49		echo "${SCRIPT}: ${DESC} succeeded"
50	fi
51}
52
53ts_ip()
54{
55	SCRIPT=$1; shift
56	DESC=$1; shift
57
58	$IP $@ 2> $STD_ERR > $STD_OUT
59        RET=$?
60
61	if [ -s $STD_ERR ] || [ "$RET" != "0" ]; then
62		ts_err "${SCRIPT}: ${DESC} failed:"
63		ts_err "command: $IP $@"
64		ts_err "stderr output:"
65		ts_err_cat $STD_ERR
66		if [ -s $STD_OUT ]; then
67			ts_err "stdout output:"
68			ts_err_cat $STD_OUT
69		fi
70	elif [ -s $STD_OUT ]; then
71		echo "${SCRIPT}: ${DESC} succeeded with output:"
72		cat $STD_OUT
73	else
74		echo "${SCRIPT}: ${DESC} succeeded"
75	fi
76}
77
78ts_qdisc_available()
79{
80	HELPOUT=`$TC qdisc add $1 help 2>&1`
81	if [ "`echo $HELPOUT | grep \"^Unknown qdisc\"`" ]; then
82		return 0;
83	else
84		return 1;
85	fi
86}
87
88rand_dev()
89{
90    echo "dev-$(tr -dc "[:alpha:]" < /dev/urandom | head -c 6)"
91}
92
93pr_failed()
94{
95	echo " [FAILED]"
96	ts_err "matching failed"
97}
98
99pr_success()
100{
101	echo " [SUCCESS]"
102}
103
104test_on()
105{
106	echo -n "test on: \"$1\""
107	if cat "$STD_OUT" | grep -qE "$1"
108	then
109		pr_success
110	else
111		pr_failed
112	fi
113}
114
115test_on_not()
116{
117	echo -n "test on: \"$1\""
118	if cat "$STD_OUT" | grep -vqE "$1"
119	then
120		pr_success
121	else
122		pr_failed
123	fi
124}
125
126test_lines_count()
127{
128	echo -n "test on lines count ($1): "
129	if cat "$STD_OUT" | wc -l | grep -q "$1"
130	then
131		pr_success
132	else
133		pr_failed
134	fi
135}
136