On 06/12/2015 09:07 AM, Cui Bixuan wrote:
> * init() --> setup()
> * Use "ROD_SILENT" and "tst_check_cmds"
> * Save the iptables before the testcase and restore it after the testcase
> * Delete some useless comments
> * Delete the needless check(grep -c Chain and grep "100% packet loss")
>    in test01 and test02
> * Use "tst_resm TBROK" if remove the rule failed
>
> Signed-off-by: Cui Bixuan<cuibix...@huawei.com>
> ---
>   testcases/network/iptables/iptables_tests.sh |  111 
> ++++++-------------------
>   1 files changed, 27 insertions(+), 84 deletions(-)
>
> ...
>
>   cleanup()
>   {
> -     lsmod | grep "ip_tables" > tst_iptables.out 2>&1
> -     if [ $? -eq 0 ]; then
> -             iptables -F -t filter > tst_iptables.out 2>&1
> -             iptables -F -t nat > tst_iptables.out 2>&1
> -             iptables -F -t mangle > tst_iptables.out 2>&1
> -             rmmod -v ipt_limit ipt_multiport ipt_LOG ipt_REJECT \
> -                      iptable_mangle iptable_nat ip_conntrack \
> -                      iptable_filter ip_tables nf_nat_ipv4 nf_nat \
> -                      nf_log_ipv4 nf_log_common nf_reject_ipv4 \
> -                      nf_conntrack_ipv4 nf_defrag_ipv4 nf_conntrack \
> -                      > tst_iptables.out 2>&1

Why you removed "rmmod" part?

> ...   
> @@ -138,15 +96,7 @@ test02()
>       tst_resm TINFO "Pinging 127.0.0.1"
>       ping -c 2 127.0.0.1 > tst_iptables.out 2>&1
>       if [ $? -ne 0 ]; then
> -             grep "100% packet loss" tst_iptables.out > tst_iptables.err 2>&1
> -             if [ $? -ne 0 ]; then
> -                     tst_resm TFAIL \
> -                              "iptables did not block packets from loopback"
> -                     cat tst_iptables.err
> -                     return
> -             else
> -                     tst_resm TINFO "Ping 127.0.0.1 not successful."
> -             fi
> +             tst_resm TINFO "Ping 127.0.0.1 not successful."
>       else
>               tst_resm TFAIL "iptables did not block icmp from 127.0.0.1"
>               cat tst_iptables.out

It would be better to make it like:

if [ $? -eq 0 ]; then
     tst_rems TFAIL ...
     return
fi
tst_resm TINFO "ping failed, iptables blocked ICMP as expected"

And in test03() as well.

> @@ -156,7 +106,7 @@ test02()
>       tst_resm TINFO "Deleting icmp DROP from 127.0.0.1 rule."
>       iptables -D INPUT 1 > tst_iptables.out 2>&1
>       if [ $? -ne 0 ]; then
> -             tst_resm TFAIL "iptables did not remove the rule."
> +             tst_resm TBROK "iptables did not remove the rule."
>               cat tst_iptables.out
>               return
>       fi
> @@ -189,14 +139,7 @@ test03()
>       tst_resm TINFO "Pinging 127.0.0.1"
>       ping -c 2 127.0.0.1 > tst_iptables.out 2>&1
>       if [ $? -ne 0 ]; then
> -             grep "100% packet loss" tst_iptables.out > tst_iptables.err 2>&1
> -             if [ $? -ne 0 ]; then
> -                     tst_resm TFAIL "iptables did not block ping request."
> -                     cat tst_iptables.err
> -                     return
> -             else
> -                     tst_resm TINFO "Ping 127.0.0.1 not successful."
> -             fi
> +             tst_resm TINFO "Ping 127.0.0.1 not successful."
>       else
>               tst_resm TFAIL "iptables did not reject ping request."
>               cat tst_iptables.out
> @@ -206,7 +149,7 @@ test03()
>       tst_resm TINFO "Deleting icmp request REJECT rule."
>       iptables -D INPUT 1 > tst_iptables.out 2>&1
>       if [ $? -ne 0 ]; then
> -             tst_resm TFAIL "iptables did not remove the rule."
> +             tst_resm TBROK "iptables did not remove the rule."
>               cat tst_iptables.out
>               return

Why TFAIL changed to TBROK... or do you want the test to exit at that 
point? if yes, you need to use tst_brkm instead.


Thanks,
Alexey


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to