diff options
author | Shuah Khan (Samsung OSG) <shuah@kernel.org> | 2018-05-04 18:34:09 -0400 |
---|---|---|
committer | Shuah Khan (Samsung OSG) <shuah@kernel.org> | 2018-05-30 17:29:06 -0400 |
commit | 57aefc7c226dae84e2724fc0229d85870a70ad24 (patch) | |
tree | d98d004db54863994417300f4a637fbb6cca0f37 /tools | |
parent | e6ee6ae4a170335d685571f38510505dd62cc6a4 (diff) |
selftests: net: return Kselftest Skip code for skipped tests
When net test is skipped because of unmet dependencies and/or unsupported
configuration, it returns 0 which is treated as a pass by the Kselftest
framework. This leads to false positive result even when the test could
not be run.
Change it to return kselftest skip code when a test gets skipped to
clearly report that the test could not be run.
Kselftest framework SKIP code is 4 and the framework prints appropriate
messages to indicate that the test is skipped.
Change psock_tpacket to use ksft_exit_skip() when a non-root user runs
the test and add an explicit check for root and a clear message, instead
of failing the test when /sys/power/state file open fails.
Signed-off-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/testing/selftests/net/fib_tests.sh | 8 | ||||
-rwxr-xr-x | tools/testing/selftests/net/netdevice.sh | 16 | ||||
-rwxr-xr-x | tools/testing/selftests/net/pmtu.sh | 5 | ||||
-rw-r--r-- | tools/testing/selftests/net/psock_tpacket.c | 4 | ||||
-rwxr-xr-x | tools/testing/selftests/net/rtnetlink.sh | 31 |
5 files changed, 39 insertions, 25 deletions
diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index 9164e60d4b66..5baac82b9287 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh | |||
@@ -5,6 +5,8 @@ | |||
5 | # different events. | 5 | # different events. |
6 | 6 | ||
7 | ret=0 | 7 | ret=0 |
8 | # Kselftest framework requirement - SKIP code is 4. | ||
9 | ksft_skip=4 | ||
8 | 10 | ||
9 | VERBOSE=${VERBOSE:=0} | 11 | VERBOSE=${VERBOSE:=0} |
10 | PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} | 12 | PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} |
@@ -579,18 +581,18 @@ fib_test() | |||
579 | 581 | ||
580 | if [ "$(id -u)" -ne 0 ];then | 582 | if [ "$(id -u)" -ne 0 ];then |
581 | echo "SKIP: Need root privileges" | 583 | echo "SKIP: Need root privileges" |
582 | exit 0 | 584 | exit $ksft_skip; |
583 | fi | 585 | fi |
584 | 586 | ||
585 | if [ ! -x "$(command -v ip)" ]; then | 587 | if [ ! -x "$(command -v ip)" ]; then |
586 | echo "SKIP: Could not run test without ip tool" | 588 | echo "SKIP: Could not run test without ip tool" |
587 | exit 0 | 589 | exit $ksft_skip |
588 | fi | 590 | fi |
589 | 591 | ||
590 | ip route help 2>&1 | grep -q fibmatch | 592 | ip route help 2>&1 | grep -q fibmatch |
591 | if [ $? -ne 0 ]; then | 593 | if [ $? -ne 0 ]; then |
592 | echo "SKIP: iproute2 too old, missing fibmatch" | 594 | echo "SKIP: iproute2 too old, missing fibmatch" |
593 | exit 0 | 595 | exit $ksft_skip |
594 | fi | 596 | fi |
595 | 597 | ||
596 | # start clean | 598 | # start clean |
diff --git a/tools/testing/selftests/net/netdevice.sh b/tools/testing/selftests/net/netdevice.sh index 903679e0ff31..e3afcb424710 100755 --- a/tools/testing/selftests/net/netdevice.sh +++ b/tools/testing/selftests/net/netdevice.sh | |||
@@ -8,6 +8,9 @@ | |||
8 | # if not they probably have failed earlier in the boot process and their logged error will be catched by another test | 8 | # if not they probably have failed earlier in the boot process and their logged error will be catched by another test |
9 | # | 9 | # |
10 | 10 | ||
11 | # Kselftest framework requirement - SKIP code is 4. | ||
12 | ksft_skip=4 | ||
13 | |||
11 | # this function will try to up the interface | 14 | # this function will try to up the interface |
12 | # if already up, nothing done | 15 | # if already up, nothing done |
13 | # arg1: network interface name | 16 | # arg1: network interface name |
@@ -18,7 +21,7 @@ kci_net_start() | |||
18 | ip link show "$netdev" |grep -q UP | 21 | ip link show "$netdev" |grep -q UP |
19 | if [ $? -eq 0 ];then | 22 | if [ $? -eq 0 ];then |
20 | echo "SKIP: $netdev: interface already up" | 23 | echo "SKIP: $netdev: interface already up" |
21 | return 0 | 24 | return $ksft_skip |
22 | fi | 25 | fi |
23 | 26 | ||
24 | ip link set "$netdev" up | 27 | ip link set "$netdev" up |
@@ -61,12 +64,12 @@ kci_net_setup() | |||
61 | ip address show "$netdev" |grep '^[[:space:]]*inet' | 64 | ip address show "$netdev" |grep '^[[:space:]]*inet' |
62 | if [ $? -eq 0 ];then | 65 | if [ $? -eq 0 ];then |
63 | echo "SKIP: $netdev: already have an IP" | 66 | echo "SKIP: $netdev: already have an IP" |
64 | return 0 | 67 | return $ksft_skip |
65 | fi | 68 | fi |
66 | 69 | ||
67 | # TODO what ipaddr to set ? DHCP ? | 70 | # TODO what ipaddr to set ? DHCP ? |
68 | echo "SKIP: $netdev: set IP address" | 71 | echo "SKIP: $netdev: set IP address" |
69 | return 0 | 72 | return $ksft_skip |
70 | } | 73 | } |
71 | 74 | ||
72 | # test an ethtool command | 75 | # test an ethtool command |
@@ -84,6 +87,7 @@ kci_netdev_ethtool_test() | |||
84 | if [ $ret -ne 0 ];then | 87 | if [ $ret -ne 0 ];then |
85 | if [ $ret -eq "$1" ];then | 88 | if [ $ret -eq "$1" ];then |
86 | echo "SKIP: $netdev: ethtool $2 not supported" | 89 | echo "SKIP: $netdev: ethtool $2 not supported" |
90 | return $ksft_skip | ||
87 | else | 91 | else |
88 | echo "FAIL: $netdev: ethtool $2" | 92 | echo "FAIL: $netdev: ethtool $2" |
89 | return 1 | 93 | return 1 |
@@ -104,7 +108,7 @@ kci_netdev_ethtool() | |||
104 | ethtool --version 2>/dev/null >/dev/null | 108 | ethtool --version 2>/dev/null >/dev/null |
105 | if [ $? -ne 0 ];then | 109 | if [ $? -ne 0 ];then |
106 | echo "SKIP: ethtool not present" | 110 | echo "SKIP: ethtool not present" |
107 | return 1 | 111 | return $ksft_skip |
108 | fi | 112 | fi |
109 | 113 | ||
110 | TMP_ETHTOOL_FEATURES="$(mktemp)" | 114 | TMP_ETHTOOL_FEATURES="$(mktemp)" |
@@ -176,13 +180,13 @@ kci_test_netdev() | |||
176 | #check for needed privileges | 180 | #check for needed privileges |
177 | if [ "$(id -u)" -ne 0 ];then | 181 | if [ "$(id -u)" -ne 0 ];then |
178 | echo "SKIP: Need root privileges" | 182 | echo "SKIP: Need root privileges" |
179 | exit 0 | 183 | exit $ksft_skip |
180 | fi | 184 | fi |
181 | 185 | ||
182 | ip link show 2>/dev/null >/dev/null | 186 | ip link show 2>/dev/null >/dev/null |
183 | if [ $? -ne 0 ];then | 187 | if [ $? -ne 0 ];then |
184 | echo "SKIP: Could not run test without the ip tool" | 188 | echo "SKIP: Could not run test without the ip tool" |
185 | exit 0 | 189 | exit $ksft_skip |
186 | fi | 190 | fi |
187 | 191 | ||
188 | TMP_LIST_NETDEV="$(mktemp)" | 192 | TMP_LIST_NETDEV="$(mktemp)" |
diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh index 1e428781a625..7514f93e1624 100755 --- a/tools/testing/selftests/net/pmtu.sh +++ b/tools/testing/selftests/net/pmtu.sh | |||
@@ -43,6 +43,9 @@ | |||
43 | # that MTU is properly calculated instead when MTU is not configured from | 43 | # that MTU is properly calculated instead when MTU is not configured from |
44 | # userspace | 44 | # userspace |
45 | 45 | ||
46 | # Kselftest framework requirement - SKIP code is 4. | ||
47 | ksft_skip=4 | ||
48 | |||
46 | tests=" | 49 | tests=" |
47 | pmtu_vti6_exception vti6: PMTU exceptions | 50 | pmtu_vti6_exception vti6: PMTU exceptions |
48 | pmtu_vti4_exception vti4: PMTU exceptions | 51 | pmtu_vti4_exception vti4: PMTU exceptions |
@@ -162,7 +165,7 @@ setup_xfrm6() { | |||
162 | } | 165 | } |
163 | 166 | ||
164 | setup() { | 167 | setup() { |
165 | [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return 1 | 168 | [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip |
166 | 169 | ||
167 | cleanup_done=0 | 170 | cleanup_done=0 |
168 | for arg do | 171 | for arg do |
diff --git a/tools/testing/selftests/net/psock_tpacket.c b/tools/testing/selftests/net/psock_tpacket.c index 7f6cd9fdacf3..7ec4fa4d55dc 100644 --- a/tools/testing/selftests/net/psock_tpacket.c +++ b/tools/testing/selftests/net/psock_tpacket.c | |||
@@ -60,6 +60,8 @@ | |||
60 | 60 | ||
61 | #include "psock_lib.h" | 61 | #include "psock_lib.h" |
62 | 62 | ||
63 | #include "../kselftest.h" | ||
64 | |||
63 | #ifndef bug_on | 65 | #ifndef bug_on |
64 | # define bug_on(cond) assert(!(cond)) | 66 | # define bug_on(cond) assert(!(cond)) |
65 | #endif | 67 | #endif |
@@ -825,7 +827,7 @@ static int test_tpacket(int version, int type) | |||
825 | fprintf(stderr, "test: skip %s %s since user and kernel " | 827 | fprintf(stderr, "test: skip %s %s since user and kernel " |
826 | "space have different bit width\n", | 828 | "space have different bit width\n", |
827 | tpacket_str[version], type_str[type]); | 829 | tpacket_str[version], type_str[type]); |
828 | return 0; | 830 | return KSFT_SKIP; |
829 | } | 831 | } |
830 | 832 | ||
831 | sock = pfsocket(version); | 833 | sock = pfsocket(version); |
diff --git a/tools/testing/selftests/net/rtnetlink.sh b/tools/testing/selftests/net/rtnetlink.sh index e6f485235435..fb3767844e42 100755 --- a/tools/testing/selftests/net/rtnetlink.sh +++ b/tools/testing/selftests/net/rtnetlink.sh | |||
@@ -7,6 +7,9 @@ | |||
7 | devdummy="test-dummy0" | 7 | devdummy="test-dummy0" |
8 | ret=0 | 8 | ret=0 |
9 | 9 | ||
10 | # Kselftest framework requirement - SKIP code is 4. | ||
11 | ksft_skip=4 | ||
12 | |||
10 | # set global exit status, but never reset nonzero one. | 13 | # set global exit status, but never reset nonzero one. |
11 | check_err() | 14 | check_err() |
12 | { | 15 | { |
@@ -333,7 +336,7 @@ kci_test_vrf() | |||
333 | ip link show type vrf 2>/dev/null | 336 | ip link show type vrf 2>/dev/null |
334 | if [ $? -ne 0 ]; then | 337 | if [ $? -ne 0 ]; then |
335 | echo "SKIP: vrf: iproute2 too old" | 338 | echo "SKIP: vrf: iproute2 too old" |
336 | return 0 | 339 | return $ksft_skip |
337 | fi | 340 | fi |
338 | 341 | ||
339 | ip link add "$vrfname" type vrf table 10 | 342 | ip link add "$vrfname" type vrf table 10 |
@@ -409,7 +412,7 @@ kci_test_encap_fou() | |||
409 | ip fou help 2>&1 |grep -q 'Usage: ip fou' | 412 | ip fou help 2>&1 |grep -q 'Usage: ip fou' |
410 | if [ $? -ne 0 ];then | 413 | if [ $? -ne 0 ];then |
411 | echo "SKIP: fou: iproute2 too old" | 414 | echo "SKIP: fou: iproute2 too old" |
412 | return 1 | 415 | return $ksft_skip |
413 | fi | 416 | fi |
414 | 417 | ||
415 | ip netns exec "$testns" ip fou add port 7777 ipproto 47 2>/dev/null | 418 | ip netns exec "$testns" ip fou add port 7777 ipproto 47 2>/dev/null |
@@ -444,7 +447,7 @@ kci_test_encap() | |||
444 | ip netns add "$testns" | 447 | ip netns add "$testns" |
445 | if [ $? -ne 0 ]; then | 448 | if [ $? -ne 0 ]; then |
446 | echo "SKIP encap tests: cannot add net namespace $testns" | 449 | echo "SKIP encap tests: cannot add net namespace $testns" |
447 | return 1 | 450 | return $ksft_skip |
448 | fi | 451 | fi |
449 | 452 | ||
450 | ip netns exec "$testns" ip link set lo up | 453 | ip netns exec "$testns" ip link set lo up |
@@ -469,7 +472,7 @@ kci_test_macsec() | |||
469 | ip macsec help 2>&1 | grep -q "^Usage: ip macsec" | 472 | ip macsec help 2>&1 | grep -q "^Usage: ip macsec" |
470 | if [ $? -ne 0 ]; then | 473 | if [ $? -ne 0 ]; then |
471 | echo "SKIP: macsec: iproute2 too old" | 474 | echo "SKIP: macsec: iproute2 too old" |
472 | return 0 | 475 | return $ksft_skip |
473 | fi | 476 | fi |
474 | 477 | ||
475 | ip link add link "$devdummy" "$msname" type macsec port 42 encrypt on | 478 | ip link add link "$devdummy" "$msname" type macsec port 42 encrypt on |
@@ -511,14 +514,14 @@ kci_test_gretap() | |||
511 | ip netns add "$testns" | 514 | ip netns add "$testns" |
512 | if [ $? -ne 0 ]; then | 515 | if [ $? -ne 0 ]; then |
513 | echo "SKIP gretap tests: cannot add net namespace $testns" | 516 | echo "SKIP gretap tests: cannot add net namespace $testns" |
514 | return 1 | 517 | return $ksft_skip |
515 | fi | 518 | fi |
516 | 519 | ||
517 | ip link help gretap 2>&1 | grep -q "^Usage:" | 520 | ip link help gretap 2>&1 | grep -q "^Usage:" |
518 | if [ $? -ne 0 ];then | 521 | if [ $? -ne 0 ];then |
519 | echo "SKIP: gretap: iproute2 too old" | 522 | echo "SKIP: gretap: iproute2 too old" |
520 | ip netns del "$testns" | 523 | ip netns del "$testns" |
521 | return 1 | 524 | return $ksft_skip |
522 | fi | 525 | fi |
523 | 526 | ||
524 | # test native tunnel | 527 | # test native tunnel |
@@ -561,14 +564,14 @@ kci_test_ip6gretap() | |||
561 | ip netns add "$testns" | 564 | ip netns add "$testns" |
562 | if [ $? -ne 0 ]; then | 565 | if [ $? -ne 0 ]; then |
563 | echo "SKIP ip6gretap tests: cannot add net namespace $testns" | 566 | echo "SKIP ip6gretap tests: cannot add net namespace $testns" |
564 | return 1 | 567 | return $ksft_skip |
565 | fi | 568 | fi |
566 | 569 | ||
567 | ip link help ip6gretap 2>&1 | grep -q "^Usage:" | 570 | ip link help ip6gretap 2>&1 | grep -q "^Usage:" |
568 | if [ $? -ne 0 ];then | 571 | if [ $? -ne 0 ];then |
569 | echo "SKIP: ip6gretap: iproute2 too old" | 572 | echo "SKIP: ip6gretap: iproute2 too old" |
570 | ip netns del "$testns" | 573 | ip netns del "$testns" |
571 | return 1 | 574 | return $ksft_skip |
572 | fi | 575 | fi |
573 | 576 | ||
574 | # test native tunnel | 577 | # test native tunnel |
@@ -611,13 +614,13 @@ kci_test_erspan() | |||
611 | ip link help erspan 2>&1 | grep -q "^Usage:" | 614 | ip link help erspan 2>&1 | grep -q "^Usage:" |
612 | if [ $? -ne 0 ];then | 615 | if [ $? -ne 0 ];then |
613 | echo "SKIP: erspan: iproute2 too old" | 616 | echo "SKIP: erspan: iproute2 too old" |
614 | return 1 | 617 | return $ksft_skip |
615 | fi | 618 | fi |
616 | 619 | ||
617 | ip netns add "$testns" | 620 | ip netns add "$testns" |
618 | if [ $? -ne 0 ]; then | 621 | if [ $? -ne 0 ]; then |
619 | echo "SKIP erspan tests: cannot add net namespace $testns" | 622 | echo "SKIP erspan tests: cannot add net namespace $testns" |
620 | return 1 | 623 | return $ksft_skip |
621 | fi | 624 | fi |
622 | 625 | ||
623 | # test native tunnel erspan v1 | 626 | # test native tunnel erspan v1 |
@@ -676,13 +679,13 @@ kci_test_ip6erspan() | |||
676 | ip link help ip6erspan 2>&1 | grep -q "^Usage:" | 679 | ip link help ip6erspan 2>&1 | grep -q "^Usage:" |
677 | if [ $? -ne 0 ];then | 680 | if [ $? -ne 0 ];then |
678 | echo "SKIP: ip6erspan: iproute2 too old" | 681 | echo "SKIP: ip6erspan: iproute2 too old" |
679 | return 1 | 682 | return $ksft_skip |
680 | fi | 683 | fi |
681 | 684 | ||
682 | ip netns add "$testns" | 685 | ip netns add "$testns" |
683 | if [ $? -ne 0 ]; then | 686 | if [ $? -ne 0 ]; then |
684 | echo "SKIP ip6erspan tests: cannot add net namespace $testns" | 687 | echo "SKIP ip6erspan tests: cannot add net namespace $testns" |
685 | return 1 | 688 | return $ksft_skip |
686 | fi | 689 | fi |
687 | 690 | ||
688 | # test native tunnel ip6erspan v1 | 691 | # test native tunnel ip6erspan v1 |
@@ -762,14 +765,14 @@ kci_test_rtnl() | |||
762 | #check for needed privileges | 765 | #check for needed privileges |
763 | if [ "$(id -u)" -ne 0 ];then | 766 | if [ "$(id -u)" -ne 0 ];then |
764 | echo "SKIP: Need root privileges" | 767 | echo "SKIP: Need root privileges" |
765 | exit 0 | 768 | exit $ksft_skip |
766 | fi | 769 | fi |
767 | 770 | ||
768 | for x in ip tc;do | 771 | for x in ip tc;do |
769 | $x -Version 2>/dev/null >/dev/null | 772 | $x -Version 2>/dev/null >/dev/null |
770 | if [ $? -ne 0 ];then | 773 | if [ $? -ne 0 ];then |
771 | echo "SKIP: Could not run test without the $x tool" | 774 | echo "SKIP: Could not run test without the $x tool" |
772 | exit 0 | 775 | exit $ksft_skip |
773 | fi | 776 | fi |
774 | done | 777 | done |
775 | 778 | ||