net/route: rewrite route-change-{dst, gw, if} into new API
v5 cover net/route: rewrite route-change-{dst, gw, if} into new API
Hi,
changes v4->v5:
addressed these Alexey's requests:
* tst_ipadd_un() now handles both host_id and net_id, with -h MIN,MAX, -n MIN,MAX
(instead of -b, -f, -n which handled only host_id)
* add -q to tst_add_ipaddr() (silence test output)
* introduce EXPECT_{FAIL,PASS}_BRK() to shell API and use it to stop test on first error.
@Cyril the only commit for you: "shell: Introduce EXPECT_{FAIL,PASS}_BRK()"
Kind regards,
Petr
Petr Vorel (8):
tst_net.sh: enhance tst_add_ipaddr(), add tst_del_ipaddr() tst_net.sh: Add -p option to return prefix in tst_ipaddr_un() tst_net.sh: Add -h -n options to tst_ipaddr_un()
net: Add tst_ipaddr_un.sh test
shell: Introduce EXPECT_{FAIL,PASS}_BRK() network/route: Rewrite route{4,6}-change-dst into new shell API network/route: Rewrite route{4,6}-change-gw into new shell API network/route: Rewrite route{4,6}-change-if into new API
doc/test-writing-guidelines.txt | 5 +- lib/newlib_tests/shell/net/tst_ipaddr_un.sh | 167 +++++++++ runtest/net_stress.route | 15 +- testcases/lib/tst_net.sh | 173 +++++++--- testcases/lib/tst_test.sh | 34 +- .../network/stress/route/00_Descriptions.txt | 54 +-- .../network/stress/route/route-change-dst.sh | 34 ++ .../network/stress/route/route-change-gw.sh | 39 +++ .../network/stress/route/route-change-if.sh | 90 +++++ testcases/network/stress/route/route-lib.sh | 17 + .../network/stress/route/route4-change-dst | 276 --------------- .../network/stress/route/route4-change-gw | 292 ---------------- .../network/stress/route/route4-change-if | 324 ------------------ .../network/stress/route/route6-change-dst | 272 --------------- .../network/stress/route/route6-change-gw | 292 ---------------- .../network/stress/route/route6-change-if | 323 ----------------- 16 files changed, 528 insertions(+), 1879 deletions(-) create mode 100755 lib/newlib_tests/shell/net/tst_ipaddr_un.sh create mode 100755 testcases/network/stress/route/route-change-dst.sh create mode 100755 testcases/network/stress/route/route-change-gw.sh create mode 100755 testcases/network/stress/route/route-change-if.sh create mode 100644 testcases/network/stress/route/route-lib.sh delete mode 100644 testcases/network/stress/route/route4-change-dst delete mode 100644 testcases/network/stress/route/route4-change-gw delete mode 100644 testcases/network/stress/route/route4-change-if delete mode 100644 testcases/network/stress/route/route6-change-dst delete mode 100644 testcases/network/stress/route/route6-change-gw delete mode 100644 testcases/network/stress/route/route6-change-if
Signature · 1 line
2.23.0
PATCH v5 1/8 tst_net.sh: enhance tst_add_ipaddr(), add tst_del_ipaddr()
to be reusable in tests (not just for internal tst_net.sh usage)
Added -a, -d, -q, -s options:
-a IP: IP address to be added, default value is $(tst_ipaddr)/$IPV{4,6}_{L,R}PREFIX
-d: delete address instead of adding
-q: quiet mode (don't print info)
-s: safe option, if something goes wrong, will exit with TBROK
-a and -d are intended for easier handling with IP addresses (not have to calculate dad for IPv6 when adding IP address).
-q is for limit noise in test output, when test uses many loops.
tst_del_ipaddr() which is just tst_add_ipaddr() wrapper was added mainly for better code readability.
--- testcases/lib/tst_net.sh | 50 +++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-)
testcases/lib/tst_net.sh +39 -11
@@ -1,7 +1,7 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved. -# Copyright (c) 2016-2018 Petr Vorel <[email protected]> +# Copyright (c) 2016-2019 Petr Vorel <[email protected]> # Author: Alexey Kodanev <[email protected]> [ -n "$TST_LIB_NET_LOADED" ] && return 0
@@ -447,14 +447,35 @@ tst_init_iface() tst_rhost_run -c "ip link set $iface up" } -# tst_add_ipaddr [TYPE] [LINK] -# TYPE: { lhost | rhost }; Default value is 'lhost'. -# LINK: link number starting from 0. Default value is '0'. +# tst_add_ipaddr [TYPE] [LINK] [-a IP] [-d] [-q] [-s] +# Options: +# TYPE: { lhost | rhost }, default value is 'lhost' +# LINK: link number starting from 0, default value is '0' +# -a IP: IP address to be added, default value is +# $(tst_ipaddr)/$IPV{4,6}_{L,R}PREFIX +# -d: delete address instead of adding +# -q: quiet mode (don't print info) +# -s: safe option, if something goes wrong, will exit with TBROK tst_add_ipaddr() { + local action="add" + local addr dad lsafe mask quiet rsafe + + local OPTIND + while getopts a:dqs opt; do + case "$opt" in + a) addr="$OPTARG" ;; + d) action="del" ;; + q) quiet=1 ;; + s) lsafe="ROD"; rsafe="-s" ;; + *) tst_brk TBROK "tst_add_ipaddr: unknown option: $OPTARG" ;; + esac + done + shift $((OPTIND - 1)) + local type="${1:-lhost}" local link_num="${2:-0}" - local mask dad + local iface=$(tst_iface $type $link_num) if [ "$TST_IPV6" ]; then dad="nodad"
@@ -462,17 +483,24 @@ tst_add_ipaddr() else [ "$type" = "lhost" ] && mask=$IPV4_LPREFIX || mask=$IPV4_RPREFIX fi - - local iface=$(tst_iface $type $link_num) + [ -n "$addr" ] || addr="$(tst_ipaddr $type)" + echo $addr | grep -q / || addr="$addr/$mask" if [ $type = "lhost" ]; then - tst_res_ TINFO "set local addr $(tst_ipaddr)/$mask" - ip addr add $(tst_ipaddr)/$mask dev $iface $dad + [ "$quiet" ] || tst_res_ TINFO "$action local addr $addr" + $lsafe ip addr $action $addr dev $iface $dad return $? fi - tst_res_ TINFO "set remote addr $(tst_ipaddr rhost)/$mask" - tst_rhost_run -c "ip addr add $(tst_ipaddr rhost)/$mask dev $iface $dad" + [ "$quiet" ] || tst_res_ TINFO "set remote addr $addr" + tst_rhost_run $rsafe -c "ip addr $action $addr dev $iface $dad" +} + +# tst_del_ipaddr [ tst_add_ipaddr options ] +# Delete IP address +tst_del_ipaddr() +{ + tst_add_ipaddr -d $@ } # tst_restore_ipaddr [TYPE] [LINK]
Signature · 1 line
2.23.0
PATCH v5 2/8 tst_net.sh: Add -p option to return prefix in tst_ipaddr_un()
In reply to Petr Vorel+ reformat docs a bit
--- testcases/lib/tst_net.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-)
testcases/lib/tst_net.sh +18 -13
@@ -357,28 +357,33 @@ tst_ipaddr() # Get IP address of unused network, specified either by type and counter # or by net and host. -# tst_ipaddr_un [-cCOUNTER] [TYPE] -# tst_ipaddr_un NET_ID [HOST_ID] -# TYPE: { lhost | rhost }; Default value is 'lhost'. -# COUNTER: Integer value for counting HOST_ID and NET_ID. Default is 1. -# NET_ID: Integer or hex value of net. For IPv4 is 3rd octet, for IPv6 -# is 3rd hextet. -# HOST_ID: Integer or hex value of host. For IPv4 is 4th octet, for -# IPv6 is the last hextet. Default value is 0. +# tst_ipaddr_un [-cCOUNTER] [-p] [TYPE] +# tst_ipaddr_un [-p] NET_ID [HOST_ID] +# +# TYPE: { lhost | rhost } (default: 'lhost') +# NET_ID: integer or hex value of net (IPv4: 3rd octet, IPv6: 3rd hextet) +# HOST_ID: integer or hex value of host (IPv4: 4th octet, IPv6: the last +# hextet, default: 0) +# +# OPTIONS +# -c COUNTER: integer value for counting HOST_ID and NET_ID (default: 1) +# -p: print also prefix tst_ipaddr_un() { - local counter host_id net_id max_host_id max_net_id tmp type + local counter host_id max_host_id max_net_id net_id prefix tmp type local OPTIND - while getopts "c:" opt; do + while getopts "c:p" opt; do case $opt in c) counter="$OPTARG";; + p) [ "$TST_IPV6" ] && prefix="/64" || prefix="/24";; esac done shift $(($OPTIND - 1)) [ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255 + # counter if [ $# -eq 0 -o "$1" = "lhost" -o "$1" = "rhost" ]; then [ -z "$counter" ] && counter=1 [ $counter -lt 1 ] && counter=1
@@ -394,7 +399,7 @@ tst_ipaddr_un() host_id=$max_host_id net_id=$((net_id - 1)) fi - else + else # net_id & host_id net_id="$1" host_id="${2:-0}" if [ "$TST_IPV6" ]; then
@@ -409,14 +414,14 @@ tst_ipaddr_un() host_id=$((host_id % max_net_id)) if [ -z "$TST_IPV6" ]; then - echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}" + echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}${prefix}" return fi [ $host_id -gt 0 ] && host_id="$(printf %x $host_id)" || host_id= [ $net_id -gt 0 ] && net_id="$(printf %x $net_id)" || net_id= [ "$net_id" ] && net_id=":$net_id" - echo "${IPV6_NET32_UNUSED}${net_id}::${host_id}" + echo "${IPV6_NET32_UNUSED}${net_id}::${host_id}${prefix}" } # tst_init_iface [TYPE] [LINK]
Signature · 1 line
2.23.0
PATCH v5 3/8 tst_net.sh: Add -h -n options to tst_ipaddr_un()
In reply to Petr Vorelto limit HOST_ID and NET_ID:
-h: specify *host* address range (HOST_ID)
-h MIN,MAX or -h MIN or -h ,MAX
-n: specify *network* address range (NET_ID)
-n MIN,MAX or -n MIN or -n ,MAX
These options are important for looping over max HOST_ID or NET_ID (255 resp. 0xffff for IPv6), when different than the default range.
NOTE: The default range for host_id & net_id changed from <0, 254 resp. 65534> to <0, 254 resp. 65535>: broadcast bit was added.
For backwards compatibility -n must be used.
But non of the code used host_id & net_id in loop => no change needed.
--- testcases/lib/tst_net.sh | 98 ++++++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 24 deletions(-)
testcases/lib/tst_net.sh +74 -24
@@ -355,50 +355,102 @@ tst_ipaddr() fi } -# Get IP address of unused network, specified either by type and counter +# Get IP address of unused network, specified either counter and type # or by net and host. -# tst_ipaddr_un [-cCOUNTER] [-p] [TYPE] -# tst_ipaddr_un [-p] NET_ID [HOST_ID] +# counter mode: +# tst_ipaddr_un [-h MIN,MAX] [-n MIN,MAX] [-p] [-c COUNTER] [TYPE] +# net & host mode: +# tst_ipaddr_un [-h MIN,MAX] [-n MIN,MAX] [-p] NET_ID [HOST_ID] # # TYPE: { lhost | rhost } (default: 'lhost') -# NET_ID: integer or hex value of net (IPv4: 3rd octet, IPv6: 3rd hextet) -# HOST_ID: integer or hex value of host (IPv4: 4th octet, IPv6: the last -# hextet, default: 0) +# NET_ID: integer or hex value of net (IPv4: 3rd octet <0,255>, IPv6: 3rd +# hextet <0,65535>) +# HOST_ID: integer or hex value of host (IPv4: 4th octet <0,255>, IPv6: the +# last hextet <0, 65535>, default: 0) # # OPTIONS # -c COUNTER: integer value for counting HOST_ID and NET_ID (default: 1) +# +# -h: specify *host* address range (HOST_ID) +# -h MIN,MAX or -h MIN or -h ,MAX +# +# -n: specify *network* address range (NET_ID) +# -n MIN,MAX or -n MIN or -n ,MAX +# # -p: print also prefix tst_ipaddr_un() { - local counter host_id max_host_id max_net_id net_id prefix tmp type - local OPTIND + local default_max=255 + [ "$TST_IPV6" ] && default_max=65535 + local max_net_id=$default_max + local min_net_id=0 - while getopts "c:p" opt; do + local counter host_id host_range is_counter max_host_id min_host_id net_id prefix tmp type + + local OPTIND + while getopts "c:h:n:p" opt; do case $opt in c) counter="$OPTARG";; + h) + if echo $OPTARG | grep -q ','; then # 'min,max' or 'min,' or ',max' + min_host_id="$(echo $OPTARG | cut -d, -f1)" + max_host_id="$(echo $OPTARG | cut -d, -f2)" + else # min + min_host_id="$OPTARG" + fi + ;; + n) + if echo $OPTARG | grep -q ','; then # 'min,max' or 'min,' or ',max' + min_net_id="$(echo $OPTARG | cut -d, -f1)" + max_net_id="$(echo $OPTARG | cut -d, -f2)" + else # min + min_net_id="$OPTARG" + fi + ;; + m) + ! tst_is_int "$OPTARG" || [ "$OPTARG" -lt 0 ]|| [ "$OPTARG" -gt $max_net_id ] && \ + tst_brk TBROK "tst_ipaddr_un: -m must be integer <0,$max_net_id> ($OPTARG)" + [ "$OPTARG" -gt $max_net_id ] && \ + tst_brk_ TBROK "tst_ipaddr_un: -m cannot be higher than $max_net_id ($OPTARG)" + max_host_id="$OPTARG" + ;; p) [ "$TST_IPV6" ] && prefix="/64" || prefix="/24";; esac done shift $(($OPTIND - 1)) + [ $# -eq 0 -o "$1" = "lhost" -o "$1" = "rhost" ] && is_counter=1 - [ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255 + if [ -z "$min_host_id" ]; then + [ "$is_counter" ] && min_host_id=1 || min_host_id=0 + fi + if [ -z "$max_host_id" ]; then + [ "$is_counter" ] && max_host_id=$((default_max - 1)) || max_host_id=$default_max + fi + + ! tst_is_int "$min_host_id" || ! tst_is_int "$max_host_id" || \ + [ $min_host_id -lt 0 -o $min_host_id -gt $default_max ] || \ + [ $max_host_id -lt 0 -o $max_host_id -gt $default_max ] && \ + tst_brk TBROK "tst_ipaddr_un: HOST_ID must be int in range <0,$default_max> ($min_host_id,$max_host_id)" + ! tst_is_int "$min_net_id" || ! tst_is_int "$max_net_id" || \ + [ $min_net_id -lt 0 -o $min_net_id -gt $default_max ] || \ + [ $max_net_id -lt 0 -o $max_net_id -gt $default_max ] && \ + tst_brk TBROK "tst_ipaddr_un: NET_ID must be int in range <0,$default_max> ($min_net_id,$max_net_id)" + + [ $min_host_id -gt $max_host_id ] && \ + tst_brk TBROK "tst_ipaddr_un: max HOST_ID ($max_host_id) must be >= min HOST_ID ($min_host_id)" + [ $min_net_id -gt $max_net_id ] && \ + tst_brk TBROK "tst_ipaddr_un: max NET_ID ($max_net_id) must be >= min NET_ID ($min_net_id)" # counter - if [ $# -eq 0 -o "$1" = "lhost" -o "$1" = "rhost" ]; then + host_range=$((max_host_id - min_host_id + 1)) + if [ "$is_counter" ]; then [ -z "$counter" ] && counter=1 [ $counter -lt 1 ] && counter=1 type="${1:-lhost}" - max_host_id=$((max_net_id - 1)) tmp=$((counter * 2)) [ "$type" = "rhost" ] && tmp=$((tmp - 1)) - - host_id=$((tmp % max_host_id)) - net_id=$((tmp / max_host_id)) - - if [ $host_id -eq 0 ]; then - host_id=$max_host_id - net_id=$((net_id - 1)) - fi + net_id=$(((tmp - 1) / host_range)) + host_id=$((tmp - net_id * host_range + min_host_id - 1)) else # net_id & host_id net_id="$1" host_id="${2:-0}"
@@ -406,12 +458,10 @@ tst_ipaddr_un() net_id=$(printf %d $net_id) host_id=$(printf %d $host_id) fi - [ $net_id -lt 0 ] && net_id=0 - [ $host_id -lt 0 ] && host_id=1 + host_id=$((host_id % host_range + min_host_id)) fi - net_id=$((net_id % max_net_id)) - host_id=$((host_id % max_net_id)) + net_id=$((net_id % (max_net_id - min_net_id + 1) + min_net_id)) if [ -z "$TST_IPV6" ]; then echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}${prefix}"
Signature · 1 line
2.23.0
PATCH v5 4/8 net: Add tst_ipaddr_un.sh test
In reply to Petr VorelTesting tst_ipaddr_un() function from network shell API (tst_net.sh).
--- lib/newlib_tests/shell/net/tst_ipaddr_un.sh | 167 ++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100755 lib/newlib_tests/shell/net/tst_ipaddr_un.sh
lib/newlib_tests/shell/net/tst_ipaddr_un.sh new file +167 -0
@@ -0,0 +1,167 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 Petr Vorel <[email protected]> + +TST_TESTFUNC=do_test +TST_CNT=2 +TST_NEEDS_CMDS="cut" + +PATH="$(dirname $0)/../../../../testcases/lib/:$PATH" + +RHOST="foo" +. tst_net.sh + +IPV4_DATA=" +0 0|10.23.0.0 +0 1|10.23.0.1 +1 0|10.23.1.0 +1 1|10.23.1.1 +1 2|10.23.1.2 +2 2|10.23.2.2 +1 3|10.23.1.3 +3 3|10.23.3.3 +1 128|10.23.1.128 +128 128|10.23.128.128 +1 254|10.23.1.254 +254 254|10.23.254.254 +1 255|10.23.1.255 +255 255|10.23.255.255 +1 256|10.23.1.0 +256 256|10.23.0.0 +1 257|10.23.1.1 +257 257|10.23.1.1 + +-c 0|10.23.0.2 +-c 0 lhost|10.23.0.2 +-c 0 rhost|10.23.0.1 + +-c 1|10.23.0.2 +-c 1 rhost|10.23.0.1 +-c 2|10.23.0.4 +-c 2 rhost|10.23.0.3 +-c 127|10.23.0.254 +-c 127 rhost|10.23.0.253 +-c 128|10.23.1.2 +-c 128 rhost|10.23.1.1 +-c 254|10.23.1.254 +-c 254 rhost|10.23.1.253 +-c 255|10.23.2.2 +-c 255 rhost|10.23.2.1 + +-c 0 -h1,255|10.23.0.2 +-c 0 -h1,255 rhost|10.23.0.1 +-c 1 -h1,255|10.23.0.2 +-c 1 -h1,255 rhost|10.23.0.1 +-c 127 -h1,255|10.23.0.254 +-c 127 -h1,255 rhost|10.23.0.253 +-c 128 -h1,255|10.23.1.1 +-c 128 -h1,255 rhost|10.23.0.255 +-c 255 -h1,255|10.23.1.255 +-c 255 -h1,255 rhost|10.23.1.254 +-c 256 -h1,255|10.23.2.2 +-c 256 -h1,255 rhost|10.23.2.1 + +-c1 -h 2,8 -n 2,8|10.23.2.3 +-c1 -h 2,8 -n 2,8 rhost|10.23.2.2 +-c2 -h 2,8 -n 2,8|10.23.2.5 +-c2 -h 2,8 -n 2,8 rhost|10.23.2.4 + +-c1 -n 22,44|10.23.22.2 +-c1 -n 22,44 rhost|10.23.22.1 +-c2 -n 22,44|10.23.22.4 +-c2 -n 22,44 rhost|10.23.22.3 +" + +IPV6_DATA=" +0 0|fd00:23:: +0 1|fd00:23::1 +1 0|fd00:23:1:: +1 1|fd00:23:1::1 +1 2|fd00:23:1::2 +2 2|fd00:23:2::2 +1 3|fd00:23:1::3 +3 3|fd00:23:3::3 +1 32767|fd00:23:1::7fff +32767 32767|fd00:23:7fff::7fff +1 65534|fd00:23:1::fffe +65534 65534|fd00:23:fffe::fffe +1 65535|fd00:23:1::ffff +65535 65535|fd00:23:ffff::ffff +1 65536|fd00:23:1:: +65536 65536|fd00:23:: +1 65537|fd00:23:1::1 +65537 65537|fd00:23:1::1 + +-c 0|fd00:23::2 +-c 0 lhost|fd00:23::2 +-c 0 rhost|fd00:23::1 + +-c 1|fd00:23::2 +-c 1 rhost|fd00:23::1 +-c 2|fd00:23::4 +-c 2 rhost|fd00:23::3 +-c 32767|fd00:23::fffe +-c 32767 rhost|fd00:23::fffd +-c 32768|fd00:23:1::2 +-c 32768 rhost|fd00:23:1::1 +-c 65534|fd00:23:1::fffe +-c 65534 rhost|fd00:23:1::fffd +-c 65535|fd00:23:2::2 +-c 65535 rhost|fd00:23:2::1 + +-c 0 -h1,65535|fd00:23::2 +-c 0 -h1,65535 rhost|fd00:23::1 +-c 1 -h1,65535|fd00:23::2 +-c 1 -h1,65535 rhost|fd00:23::1 +-c 32767 -h1,65535|fd00:23::fffe +-c 32767 -h1,65535 rhost|fd00:23::fffd +-c 32768 -h1,65535|fd00:23:1::1 +-c 32768 -h1,65535 rhost|fd00:23::ffff +-c 65535 -h1,65535|fd00:23:1::ffff +-c 65535 -h1,65535 rhost|fd00:23:1::fffe +-c 65536 -h1,65535|fd00:23:2::2 +-c 65536 -h1,65535 rhost|fd00:23:2::1 + +-c1 -h 2,8 -n 2,8|fd00:23:2::3 +-c1 -h 2,8 -n 2,8 rhost|fd00:23:2::2 +-c2 -h 2,8 -n 2,8|fd00:23:2::5 +-c2 -h 2,8 -n 2,8 rhost|fd00:23:2::4 + +-c1 -n 22,44|fd00:23:16::2 +-c1 -n 22,44 rhost|fd00:23:16::1 +-c2 -n 22,44|fd00:23:16::4 +-c2 -n 22,44 rhost|fd00:23:16::3 +" + +test_tst_ipaddr_un() +{ + local data cmd i result + local var="$1" + + tst_res TINFO "Testing for IPv${TST_IPVER}, data: \$$var" + + eval data="\$$var" + IFS=" +" + for i in $data; do + cmd="tst_ipaddr_un $(echo $i | cut -d'|' -f 1)" + result="$(echo $i | cut -d'|' -f 2)" + tst_res TINFO "testing $cmd" + EXPECT_PASS "[ '$(eval $cmd)' = '$result' ]" + done +} + +do_test2() +{ + test_tst_ipaddr_un "IPV${TST_IPVER}_DATA" +} + +do_test() +{ + case $1 in + 1) TST_IPV6= TST_IPVER=4 do_test2;; + 2) TST_IPV6=6 TST_IPVER=6 do_test2;; + esac +} + +tst_run
Signature · 1 line
2.23.0
PATCH v5 5/8 shell: Introduce EXPECT_{FAIL,PASS}_BRK()
In reply to Petr Vorel--- doc/test-writing-guidelines.txt | 5 ++++- testcases/lib/tst_test.sh | 34 +++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-)
doc/test-writing-guidelines.txt +4 -1
@@ -2428,7 +2428,7 @@ Note the '>' is escaped with '\', this causes that the '>' and filename are passed to the 'ROD' function as parameters and the 'ROD' function contains code to split '$@' on '>' and redirects the output to the file. -EXPECT_PASS and EXPECT_FAIL +EXPECT_PASS{,_BRK} and EXPECT_FAIL{,_BRK} +++++++++++++++++++++++++++ [source,sh]
@@ -2443,6 +2443,9 @@ and 'tst_resm TFAIL' otherwise. 'EXPECT_FAIL' does vice versa. Output redirection rules are the same as for the 'ROD' function. In addition to that, 'EXPECT_FAIL' always redirects the command's stderr to '/dev/null'. +There are also 'EXPECT_PASS_BRK' and 'EXPECT_FAIL_BRK', which works the same way +except breaking a test when unexpected action happen. + tst_kvcmp +++++++++
testcases/lib/tst_test.sh +30 -4
@@ -139,27 +139,53 @@ ROD() fi } -EXPECT_PASS() +_tst_expect_pass() { + local fnc="$1" + shift + tst_rod "$@" if [ $? -eq 0 ]; then tst_res TPASS "$@ passed as expected" else - tst_res TFAIL "$@ failed unexpectedly" + $fnc TFAIL "$@ failed unexpectedly" fi } -EXPECT_FAIL() +_tst_expect_fail() { + local fnc="$1" + shift + # redirect stderr since we expect the command to fail tst_rod "$@" 2> /dev/null if [ $? -ne 0 ]; then tst_res TPASS "$@ failed as expected" else - tst_res TFAIL "$@ passed unexpectedly" + $fnc TFAIL "$@ passed unexpectedly" fi } +EXPECT_PASS() +{ + _tst_expect_pass tst_res "$@" +} + +EXPECT_PASS_BRK() +{ + _tst_expect_pass tst_brk "$@" +} + +EXPECT_FAIL() +{ + _tst_expect_fail tst_res "$@" +} + +EXPECT_FAIL_BRK() +{ + _tst_expect_fail tst_brk "$@" +} + TST_RETRY_FN_EXP_BACKOFF() { local tst_fun="$1"
Signature · 1 line
2.23.0
PATCH v5 5/8 shell: Introduce EXPECT_{FAIL,PASS}_BRK()
Hi!
Looks good, acked.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v5 6/8 network/route: Rewrite route{4, 6}-change-dst into new shell API
In reply to Petr Vorel* Drop route command (use just ip command), support both IPv4 and IPv6
* Add route-lib.sh (will be used in other route-change-*)
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)
--- runtest/net_stress.route | 7 +- .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-dst.sh | 34 +++ testcases/network/stress/route/route-lib.sh | 17 ++ .../network/stress/route/route4-change-dst | 276 ------------------ .../network/stress/route/route6-change-dst | 272 ----------------- 6 files changed, 56 insertions(+), 568 deletions(-) create mode 100755 testcases/network/stress/route/route-change-dst.sh create mode 100644 testcases/network/stress/route/route-lib.sh delete mode 100644 testcases/network/stress/route/route4-change-dst delete mode 100644 testcases/network/stress/route/route6-change-dst
runtest/net_stress.route +2 -5
@@ -1,14 +1,11 @@ -# # Stress test for routing table -# - -route4-change-dst route4-change-dst +route4-change-dst route-change-dst.sh route4-change-gw route4-change-gw route4-change-if route4-change-if route4-redirect route4-redirect route4-rmmod route4-rmmod -route6-change-dst route6-change-dst +route6-change-dst route-change-dst.sh -6 route6-change-gw route6-change-gw route6-change-if route6-change-if route6-redirect route6-redirect
testcases/network/stress/route/00_Descriptions.txt +3 -15
@@ -1,10 +1,6 @@ -route4-change-dst01 - Verify the kernel is not crashed when the destination of an IPv4 route - is changed frequently by route command - -route4-change-dst02 - Verify the kernel is not crashed when the destination of an IPv4 route - is changed frequently by ip command +route{4,6}-change-dst + Verify the IPv4/IPv6 is not broken when ip command changes route + destination many times route4-change-gw01 Verify the kernel is not crashed when the gateway of an IPv4 route is
@@ -35,14 +31,6 @@ route4-rmmod02 then it is deleted by the removing network driver -route6-change-dst01 - Verify the kernel is not crashed when the destination of an IPv6 route - is changed frequently by route command - -route6-change-dst02 - Verify the kernel is not crashed when the destination of an IPv6 route - is changed frequently by ip command - route6-change-gw01 Verify the kernel is not crashed when the gateway of an IPv6 route is changed frequently by route command
testcases/network/stress/route/route-change-dst.sh new file +34 -0
@@ -0,0 +1,34 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 Petr Vorel <[email protected]> +# Copyright (c) International Business Machines Corp., 2006 +# Author: Mitsuru Chinen <[email protected]> +# Rewrite into new shell API: Petr Vorel +# +# Change route destination +# lhost: 10.0.0.2, rhost: 10.23.x.1 + +TST_TESTFUNC="test_dst" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route destination $NS_TIMES times" +} + +test_dst() +{ + local iface="$(tst_iface)" + local rt="$(tst_ipaddr_un -p $1)" + local rhost="$(tst_ipaddr_un $1 1)" + + tst_res TINFO "testing route '$rt'" + + tst_add_ipaddr -s -q -a $rhost rhost + ROD ip route add $rt dev $iface + EXPECT_PASS_BRK ping$TST_IPV6 -c1 -I $(tst_ipaddr) $rhost \>/dev/null + ROD ip route del $rt dev $iface + tst_del_ipaddr -s -q -a $rhost rhost +} + +tst_run
testcases/network/stress/route/route-lib.sh new file +17 -0
@@ -0,0 +1,17 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 Petr Vorel <[email protected]> + +TST_NEEDS_ROOT=1 +TST_SETUP="setup" +TST_CLEANUP="route_cleanup" +TST_NEEDS_CMDS="ip" +TST_CNT=$NS_TIMES + +. tst_net.sh + +route_cleanup() +{ + tst_restore_ipaddr + tst_restore_ipaddr rhost +}
testcases/network/stress/route/route4-change-dst deleted +0 -276
276 lines not on this page · raw message
testcases/network/stress/route/route6-change-dst deleted +0 -272
272 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH v5 7/8 network/route: Rewrite route{4, 6}-change-gw into new shell API
In reply to Petr Vorel* Drop route command (use just ip command), support both IPv4 and IPv6
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)
--- runtest/net_stress.route | 4 +- .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-gw.sh | 39 +++ .../network/stress/route/route4-change-gw | 292 ------------------ .../network/stress/route/route6-change-gw | 292 ------------------ 5 files changed, 44 insertions(+), 601 deletions(-) create mode 100755 testcases/network/stress/route/route-change-gw.sh delete mode 100644 testcases/network/stress/route/route4-change-gw delete mode 100644 testcases/network/stress/route/route6-change-gw
runtest/net_stress.route +2 -2
@@ -1,12 +1,12 @@ # Stress test for routing table route4-change-dst route-change-dst.sh -route4-change-gw route4-change-gw +route4-change-gw route-change-gw.sh route4-change-if route4-change-if route4-redirect route4-redirect route4-rmmod route4-rmmod route6-change-dst route-change-dst.sh -6 -route6-change-gw route6-change-gw +route6-change-gw route-change-gw.sh -6 route6-change-if route6-change-if route6-redirect route6-redirect route6-rmmod route6-rmmod
testcases/network/stress/route/00_Descriptions.txt +3 -15
@@ -2,13 +2,9 @@ route{4,6}-change-dst Verify the IPv4/IPv6 is not broken when ip command changes route destination many times -route4-change-gw01 - Verify the kernel is not crashed when the gateway of an IPv4 route is - changed frequently by route command - -route4-change-gw02 - Verify the kernel is not crashed when the gateway of an IPv4 route is - changed frequently by ip command +route{4,6}-change-gw + Verify the IPv4/IPv6 is not broken when ip command changes route + gateway many times route4-change-if01 Verify the kernel is not crashed when the interface of an IPv4 route is
@@ -31,14 +27,6 @@ route4-rmmod02 then it is deleted by the removing network driver -route6-change-gw01 - Verify the kernel is not crashed when the gateway of an IPv6 route is - changed frequently by route command - -route6-change-gw02 - Verify the kernel is not crashed when the gateway of an IPv6 route is - changed frequently by ip command - route6-change-if01 Verify the kernel is not crashed when the interface of an IPv6 route is changed frequently by route command
testcases/network/stress/route/route-change-gw.sh new file +39 -0
@@ -0,0 +1,39 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 Petr Vorel <[email protected]> +# Copyright (c) International Business Machines Corp., 2006 +# Author: Mitsuru Chinen <[email protected]> +# Rewrite into new shell API: Petr Vorel +# +# Change route gateway +# lhost: 10.23.x.2, gw (on rhost): 10.23.x.1, rhost: 10.23.0.1 + +TST_TESTFUNC="test_gw" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" + + rt="$(tst_ipaddr_un -p 0 0)" + lhost="$(tst_ipaddr_un 1 1)" + rhost="$(tst_ipaddr_un 0 1)" + tst_add_ipaddr -s -q -a $lhost + tst_add_ipaddr -s -q -a $rhost rhost +} + +test_gw() +{ + local gw="$(tst_ipaddr_un -h 2,254 1 $(($1 + 1)))" + local iface="$(tst_iface)" + + tst_res TINFO "testing route over gateway '$gw'" + + tst_add_ipaddr -s -q -a $gw rhost + ROD ip route add $rt dev $iface via $gw + EXPECT_PASS_BRK ping$TST_IPV6 -c1 -I $lhost $rhost \>/dev/null + ROD ip route del $rt dev $iface via $gw + tst_del_ipaddr -s -q -a $gw rhost +} + +tst_run
testcases/network/stress/route/route4-change-gw deleted +0 -292
292 lines not on this page · raw message
testcases/network/stress/route/route6-change-gw deleted +0 -292
292 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH v5 8/8 network/route: Rewrite route{4, 6}-change-if into new API
In reply to Petr Vorel* Drop route command (use just ip command), support both IPv4 and IPv6
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)
* Add tst_get_ifaces_cnt() into tst_net.sh
--- runtest/net_stress.route | 4 +- testcases/lib/tst_net.sh | 8 + .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-if.sh | 90 +++++ .../network/stress/route/route4-change-if | 324 ------------------ .../network/stress/route/route6-change-if | 323 ----------------- 6 files changed, 103 insertions(+), 664 deletions(-) create mode 100755 testcases/network/stress/route/route-change-if.sh delete mode 100644 testcases/network/stress/route/route4-change-if delete mode 100644 testcases/network/stress/route/route6-change-if
runtest/net_stress.route +2 -2
@@ -1,12 +1,12 @@ # Stress test for routing table route4-change-dst route-change-dst.sh route4-change-gw route-change-gw.sh -route4-change-if route4-change-if +route4-change-if route-change-if.sh route4-redirect route4-redirect route4-rmmod route4-rmmod route6-change-dst route-change-dst.sh -6 route6-change-gw route-change-gw.sh -6 -route6-change-if route6-change-if +route6-change-if route-change-if.sh -6 route6-redirect route6-redirect route6-rmmod route6-rmmod
testcases/lib/tst_net.sh +8 -0
@@ -289,6 +289,14 @@ tst_get_ifaces() fi } +# Get count of test interfaces for local/remote host. +tst_get_ifaces_cnt() +{ + tst_test_cmds awk + local type="${1:-lhost}" + echo "$(tst_get_ifaces $type)" | awk '{print NF}' +} + # Get HW addresses from defined test interface names. # tst_get_hwaddrs [TYPE] # TYPE: { lhost | rhost }; Default value is 'lhost'.
testcases/network/stress/route/00_Descriptions.txt +3 -15
@@ -6,13 +6,9 @@ route{4,6}-change-gw Verify the IPv4/IPv6 is not broken when ip command changes route gateway many times -route4-change-if01 - Verify the kernel is not crashed when the interface of an IPv4 route is - changed frequently by route command - -route4-change-if02 - Verify the kernel is not crashed when the interface of an IPv4 route is - changed frequently by ip command +route{4,6}-change-if + Verify the IPv4/IPv6 is not broken when ip command changes route + interface many times route4-redirect01 Verify the kernel is not crashed when the IPv4 route is modified by
@@ -27,14 +23,6 @@ route4-rmmod02 then it is deleted by the removing network driver -route6-change-if01 - Verify the kernel is not crashed when the interface of an IPv6 route is - changed frequently by route command - -route6-change-if02 - Verify the kernel is not crashed when the interface of an IPv6 route is - changed frequently by ip command - route6-redirect01 Verify the kernel is not crashed when the IPv6 route is modified by ICMP Redirects frequently
testcases/network/stress/route/route-change-if.sh new file +90 -0
90 lines not on this page · raw message
testcases/network/stress/route/route4-change-if deleted +0 -324
324 lines not on this page · raw message
testcases/network/stress/route/route6-change-if deleted +0 -323
323 lines not on this page · raw message
Signature · 1 line
2.23.0
v5 cover net/route: rewrite route-change-{dst, gw, if} into new API
In reply to Petr VorelQuoted 8 lines · Petr Vorel
Hi,
changes
v4->v5:
addressed these Alexey's requests:
*tst_ipadd_un()now handles bothhost_idandnet_id, with -h MIN,MAX, -n MIN,MAX
(instead of -b, -f, -n which handled onlyhost_id)
Quoted 4 lines
* add -q to
tst_add_ipaddr()(silence test output)* introduce EXPECT_{FAIL,PASS}_BRK() to shell API and use it to stop test on first error.
The patches look great, thanks Petr!
Quoted 45 lines
@Cyril the only commit for you: "shell: Introduce EXPECT_{FAIL,PASS}_BRK()"
Kind regards,
PetrPetr Vorel (8):
tst_net.sh: enhancetst_add_ipaddr(), addtst_del_ipaddr()tst_net.sh: Add -p option to return prefix intst_ipaddr_un()tst_net.sh: Add -h -n options totst_ipaddr_un()
net: Addtst_ipaddr_un.shtest
shell: Introduce EXPECT_{FAIL,PASS}_BRK() network/route: Rewrite route{4,6}-change-dst into new shell API network/route: Rewrite route{4,6}-change-gw into new shell API network/route: Rewrite route{4,6}-change-if into new APIdoc/test-writing-guidelines.txt | 5 +- lib/newlib_tests/shell/net/tst_ipaddr_un.sh | 167 +++++++++ runtest/net_stress.route | 15 +- testcases/lib/tst_net.sh | 173 +++++++--- testcases/lib/tst_test.sh | 34 +- .../network/stress/route/00_Descriptions.txt | 54 +-- .../network/stress/route/route-change-dst.sh | 34 ++ .../network/stress/route/route-change-gw.sh | 39 +++ .../network/stress/route/route-change-if.sh | 90 +++++ testcases/network/stress/route/route-lib.sh | 17 + .../network/stress/route/route4-change-dst | 276 --------------- .../network/stress/route/route4-change-gw | 292 ---------------- .../network/stress/route/route4-change-if | 324 ------------------ .../network/stress/route/route6-change-dst | 272 --------------- .../network/stress/route/route6-change-gw | 292 ---------------- .../network/stress/route/route6-change-if | 323 ----------------- 16 files changed, 528 insertions(+), 1879 deletions(-) create mode 100755 lib/newlib_tests/shell/net/tst_ipaddr_un.sh create mode 100755 testcases/network/stress/route/route-change-dst.sh create mode 100755 testcases/network/stress/route/route-change-gw.sh create mode 100755 testcases/network/stress/route/route-change-if.sh create mode 100644 testcases/network/stress/route/route-lib.sh delete mode 100644 testcases/network/stress/route/route4-change-dst delete mode 100644 testcases/network/stress/route/route4-change-gw delete mode 100644 testcases/network/stress/route/route4-change-if delete mode 100644 testcases/network/stress/route/route6-change-dst delete mode 100644 testcases/network/stress/route/route6-change-gw delete mode 100644 testcases/network/stress/route/route6-change-if
v5 cover net/route: rewrite route-change-{dst, gw, if} into new API
Hi Alexey,
Quoted 9 lines · Petr Vorel
Quoted 7 lines
Hi,
changes
v4->v5:
addressed these Alexey's requests:
*tst_ipadd_un()now handles bothhost_idandnet_id, with -h MIN,MAX, -n MIN,MAX
(instead of -b, -f, -n which handled onlyhost_id)
Quoted 6 lines
Quoted 4 lines
* add -q to
tst_add_ipaddr()(silence test output)* introduce EXPECT_{FAIL,PASS}_BRK() to shell API and use it to stop test on first error.
The patches look great, thanks Petr!
Finally merged :).
Thanks a lot for many patient reviews and suggestions. I'll send another version of C netlink based tests.
Kind regards,
Petr