diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 14:18:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 14:18:53 +0000 |
commit | a0e0018c9a7ef5ce7f6d2c3ae16aecbbd16a8f67 (patch) | |
tree | 8feaf1a1932871b139b3b30be4c09c66489918be /testsuite/lib/generic.sh | |
parent | Initial commit. (diff) | |
download | iproute2-upstream/6.1.0.tar.xz iproute2-upstream/6.1.0.zip |
Adding upstream version 6.1.0.upstream/6.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | testsuite/lib/generic.sh | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/testsuite/lib/generic.sh b/testsuite/lib/generic.sh new file mode 100644 index 0000000..8b339ec --- /dev/null +++ b/testsuite/lib/generic.sh @@ -0,0 +1,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 +} |