[PATCH] selftests: xfrm: put cleanup code into a exit trap

2021-04-15 Thread Po-Hsu Lin
If the xfrm_policy.sh script takes longer than the default kselftest
framework 45 seconds timeout to run, it will be terminated and thus
leave those netns namespace files created by the test alone.

In this case a second attempt will fail with:
  # Cannot create namespace file "/run/netns/ns1": File exists

It might affect the outcome of other tests as well.

Move the netns cleanup code into an exit trap so that we can ensure
these namespace files will be removed after the test.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/xfrm_policy.sh | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/xfrm_policy.sh 
b/tools/testing/selftests/net/xfrm_policy.sh
index bdf450e..bb4632b 100755
--- a/tools/testing/selftests/net/xfrm_policy.sh
+++ b/tools/testing/selftests/net/xfrm_policy.sh
@@ -28,6 +28,11 @@ KEY_AES=0x0123456789abcdef0123456789012345
 SPI1=0x1
 SPI2=0x2
 
+cleanup() {
+for i in 1 2 3 4;do ip netns del ns$i 2>/dev/null ;done
+}
+trap cleanup EXIT
+
 do_esp_policy() {
 local ns=$1
 local me=$2
@@ -481,6 +486,4 @@ check_hthresh_repeat "policies with repeated htresh change"
 
 check_random_order ns3 "policies inserted in random order"
 
-for i in 1 2 3 4;do ip netns del ns$i;done
-
 exit $ret
-- 
2.7.4



[PATCH] selftests: fix the return value for UDP GRO test

2021-01-05 Thread Po-Hsu Lin
The udpgro.sh will always return 0 (unless the bpf selftest was not
build first) even if there are some failed sub test-cases.

Therefore the kselftest framework will report this case is OK.

Check and return the exit status of each test to make it easier to
spot real failures.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/udpgro.sh | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/tools/testing/selftests/net/udpgro.sh 
b/tools/testing/selftests/net/udpgro.sh
index ac2a30b..f8a19f5 100755
--- a/tools/testing/selftests/net/udpgro.sh
+++ b/tools/testing/selftests/net/udpgro.sh
@@ -5,6 +5,14 @@
 
 readonly PEER_NS="ns-peer-$(mktemp -u XX)"
 
+# set global exit status, but never reset nonzero one.
+check_err()
+{
+   if [ $ret -eq 0 ]; then
+   ret=$1
+   fi
+}
+
 cleanup() {
local -r jobs="$(jobs -p)"
local -r ns="$(ip netns list|grep $PEER_NS)"
@@ -44,7 +52,9 @@ run_one() {
# Hack: let bg programs complete the startup
sleep 0.1
./udpgso_bench_tx ${tx_args}
+   ret=$?
wait $(jobs -p)
+   return $ret
 }
 
 run_test() {
@@ -87,8 +97,10 @@ run_one_nat() {
 
sleep 0.1
./udpgso_bench_tx ${tx_args}
+   ret=$?
kill -INT $pid
wait $(jobs -p)
+   return $ret
 }
 
 run_one_2sock() {
@@ -110,7 +122,9 @@ run_one_2sock() {
sleep 0.1
# first UDP GSO socket should be closed at this point
./udpgso_bench_tx ${tx_args}
+   ret=$?
wait $(jobs -p)
+   return $ret
 }
 
 run_nat_test() {
@@ -131,36 +145,54 @@ run_all() {
local -r core_args="-l 4"
local -r ipv4_args="${core_args} -4 -D 192.168.1.1"
local -r ipv6_args="${core_args} -6 -D 2001:db8::1"
+   ret=0
 
echo "ipv4"
run_test "no GRO" "${ipv4_args} -M 10 -s 1400" "-4 -n 10 -l 1400"
+   check_err $?
 
# explicitly check we are not receiving UDP_SEGMENT cmsg (-S -1)
# when GRO does not take place
run_test "no GRO chk cmsg" "${ipv4_args} -M 10 -s 1400" "-4 -n 10 -l 
1400 -S -1"
+   check_err $?
 
# the GSO packets are aggregated because:
# * veth schedule napi after each xmit
# * segmentation happens in BH context, veth napi poll is delayed after
#   the transmission of the last segment
run_test "GRO" "${ipv4_args} -M 1 -s 14720 -S 0 " "-4 -n 1 -l 14720"
+   check_err $?
run_test "GRO chk cmsg" "${ipv4_args} -M 1 -s 14720 -S 0 " "-4 -n 1 -l 
14720 -S 1472"
+   check_err $?
run_test "GRO with custom segment size" "${ipv4_args} -M 1 -s 14720 -S 
500 " "-4 -n 1 -l 14720"
+   check_err $?
run_test "GRO with custom segment size cmsg" "${ipv4_args} -M 1 -s 
14720 -S 500 " "-4 -n 1 -l 14720 -S 500"
+   check_err $?
 
run_nat_test "bad GRO lookup" "${ipv4_args} -M 1 -s 14720 -S 0" "-n 10 
-l 1472"
+   check_err $?
run_2sock_test "multiple GRO socks" "${ipv4_args} -M 1 -s 14720 -S 0 " 
"-4 -n 1 -l 14720 -S 1472"
+   check_err $?
 
echo "ipv6"
run_test "no GRO" "${ipv6_args} -M 10 -s 1400" "-n 10 -l 1400"
+   check_err $?
run_test "no GRO chk cmsg" "${ipv6_args} -M 10 -s 1400" "-n 10 -l 1400 
-S -1"
+   check_err $?
run_test "GRO" "${ipv6_args} -M 1 -s 14520 -S 0" "-n 1 -l 14520"
+   check_err $?
run_test "GRO chk cmsg" "${ipv6_args} -M 1 -s 14520 -S 0" "-n 1 -l 
14520 -S 1452"
+   check_err $?
run_test "GRO with custom segment size" "${ipv6_args} -M 1 -s 14520 -S 
500" "-n 1 -l 14520"
+   check_err $?
run_test "GRO with custom segment size cmsg" "${ipv6_args} -M 1 -s 
14520 -S 500" "-n 1 -l 14520 -S 500"
+   check_err $?
 
run_nat_test "bad GRO lookup" "${ipv6_args} -M 1 -s 14520 -S 0" "-n 10 
-l 1452"
+   check_err $?
run_2sock_test "multiple GRO socks" "${ipv6_args} -M 1 -s 14520 -S 0 " 
"-n 1 -l 14520 -S 1452"
+   check_err $?
+   return $ret
 }
 
 if [ ! -f ../bpf/xdp_dummy.o ]; then
@@ -180,3 +212,5 @@ elif [[ $1 == "__subprocess_2sock" ]]; then
shift
run_one_2sock $@
 fi
+
+exit $?
-- 
2.7.4



[PATCH] selftests: xfrm: fix test return value override issue in xfrm_policy.sh

2020-12-30 Thread Po-Hsu Lin
When running this xfrm_policy.sh test script, even with some cases
marked as FAIL, the overall test result will still be PASS:

$ sudo ./xfrm_policy.sh
PASS: policy before exception matches
FAIL: expected ping to .254 to fail (exceptions)
PASS: direct policy matches (exceptions)
PASS: policy matches (exceptions)
FAIL: expected ping to .254 to fail (exceptions and block policies)
PASS: direct policy matches (exceptions and block policies)
PASS: policy matches (exceptions and block policies)
FAIL: expected ping to .254 to fail (exceptions and block policies after hresh 
changes)
PASS: direct policy matches (exceptions and block policies after hresh changes)
PASS: policy matches (exceptions and block policies after hresh changes)
FAIL: expected ping to .254 to fail (exceptions and block policies after 
hthresh change in ns3)
PASS: direct policy matches (exceptions and block policies after hthresh change 
in ns3)
PASS: policy matches (exceptions and block policies after hthresh change in ns3)
FAIL: expected ping to .254 to fail (exceptions and block policies after htresh 
change to normal)
PASS: direct policy matches (exceptions and block policies after htresh change 
to normal)
PASS: policy matches (exceptions and block policies after htresh change to 
normal)
PASS: policies with repeated htresh change
$ echo $?
0

This is because the $lret in check_xfrm() is not a local variable.
Therefore when a test failed in check_exceptions(), the non-zero $lret
will later get reset to 0 when the next test calls check_xfrm().

With this fix, the final return value will be 1. Make it easier for
testers to spot this failure.

Fixes: 39aa6928d462d0 ("xfrm: policy: fix netlink/pf_key policy lookups")
Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/xfrm_policy.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/xfrm_policy.sh 
b/tools/testing/selftests/net/xfrm_policy.sh
index 7a1bf94..5922941 100755
--- a/tools/testing/selftests/net/xfrm_policy.sh
+++ b/tools/testing/selftests/net/xfrm_policy.sh
@@ -202,7 +202,7 @@ check_xfrm() {
# 1: iptables -m policy rule count != 0
rval=$1
ip=$2
-   lret=0
+   local lret=0
 
ip netns exec ns1 ping -q -c 1 10.0.2.$ip > /dev/null
 
-- 
2.7.4



[PATCH] selftests/powerpc: make the test check in eeh-basic.sh posix compliant

2020-12-27 Thread Po-Hsu Lin
The == operand is a bash extension, thus this will fail on Ubuntu with

As the /bin/sh on Ubuntu is pointed to DASH.

Use -eq to fix this posix compatibility issue.

Fixes: 996f9e0f93f162 ("selftests/powerpc: Fix eeh-basic.sh exit codes")
Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/powerpc/eeh/eeh-basic.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/eeh/eeh-basic.sh 
b/tools/testing/selftests/powerpc/eeh/eeh-basic.sh
index 0d783e1..64779f0 100755
--- a/tools/testing/selftests/powerpc/eeh/eeh-basic.sh
+++ b/tools/testing/selftests/powerpc/eeh/eeh-basic.sh
@@ -86,5 +86,5 @@ echo "$failed devices failed to recover ($dev_count tested)"
 lspci | diff -u $pre_lspci -
 rm -f $pre_lspci
 
-test "$failed" == 0
+test "$failed" -eq 0
 exit $?
-- 
2.7.4



[PATCHv2] selftests: test_vxlan_under_vrf: mute unnecessary error message

2020-12-10 Thread Po-Hsu Lin
The cleanup function in this script that tries to delete hv-1 / hv-2
vm-1 / vm-2 netns will generate some uncessary error messages:

Cannot remove namespace file "/run/netns/hv-2": No such file or directory
Cannot remove namespace file "/run/netns/vm-1": No such file or directory
Cannot remove namespace file "/run/netns/vm-2": No such file or directory

Redirect it to /dev/null like other commands in the cleanup function
to reduce confusion.
Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/test_vxlan_under_vrf.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/test_vxlan_under_vrf.sh 
b/tools/testing/selftests/net/test_vxlan_under_vrf.sh
index 09f9ed9..534c8b7 100755
--- a/tools/testing/selftests/net/test_vxlan_under_vrf.sh
+++ b/tools/testing/selftests/net/test_vxlan_under_vrf.sh
@@ -50,7 +50,7 @@ cleanup() {
 ip link del veth-tap 2>/dev/null || true
 
 for ns in hv-1 hv-2 vm-1 vm-2; do
-ip netns del $ns || true
+ip netns del $ns 2>/dev/null || true
 done
 }
 
-- 
2.7.4



[PATCH] selftests: test_vxlan_under_vrf: mute uncessary error message

2020-12-10 Thread Po-Hsu Lin
The cleanup function in this script that tries to delete hv-1 / hv-2
vm-1 / vm-2 netns will generate some uncessary error messages:

Cannot remove namespace file "/run/netns/hv-2": No such file or directory
Cannot remove namespace file "/run/netns/vm-1": No such file or directory
Cannot remove namespace file "/run/netns/vm-2": No such file or directory

Redirect it to /dev/null like other commands in the cleanup function
to reduce confusion.
Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/test_vxlan_under_vrf.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/test_vxlan_under_vrf.sh 
b/tools/testing/selftests/net/test_vxlan_under_vrf.sh
index 09f9ed9..534c8b7 100755
--- a/tools/testing/selftests/net/test_vxlan_under_vrf.sh
+++ b/tools/testing/selftests/net/test_vxlan_under_vrf.sh
@@ -50,7 +50,7 @@ cleanup() {
 ip link del veth-tap 2>/dev/null || true
 
 for ns in hv-1 hv-2 vm-1 vm-2; do
-ip netns del $ns || true
+ip netns del $ns 2>/dev/null || true
 done
 }
 
-- 
2.7.4



[PATCH] Input: i8042 - Add ByteSpeed touchpad to noloop table

2020-11-30 Thread Po-Hsu Lin
It looks like the C15B laptop got another vendor: ByteSpeed LLC.

Avoid AUX loopback on this touchpad as well, thus input subsystem will
be able to recognize a Synaptics touchpad in the AUX port.

BugLink: https://bugs.launchpad.net/bugs/1906128
Signed-off-by: Po-Hsu Lin 
---
 drivers/input/serio/i8042-x86ia64io.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/input/serio/i8042-x86ia64io.h 
b/drivers/input/serio/i8042-x86ia64io.h
index a4c9b96..7ecb651 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -219,6 +219,10 @@ static const struct dmi_system_id __initconst 
i8042_dmi_noloop_table[] = {
DMI_MATCH(DMI_SYS_VENDOR, "PEGATRON CORPORATION"),
DMI_MATCH(DMI_PRODUCT_NAME, "C15B"),
},
+   .matches = {
+   DMI_MATCH(DMI_SYS_VENDOR, "ByteSpeed LLC"),
+   DMI_MATCH(DMI_PRODUCT_NAME, "ByteSpeed Laptop C15B"),
+   },
},
{ }
 };
-- 
2.7.4



Re: [PATCHv2] selftests/powerpc/eeh: disable kselftest timeout setting for eeh-basic

2020-11-17 Thread Po-Hsu Lin
Hello,
any update on this patch?
Or do we want to increase the timeout here?
Thanks!

On Fri, Oct 23, 2020 at 10:45 AM Po-Hsu Lin  wrote:
>
> The eeh-basic test got its own 60 seconds timeout (defined in commit
> 414f50434aa2 "selftests/eeh: Bump EEH wait time to 60s") per breakable
> device.
>
> And we have discovered that the number of breakable devices varies
> on different hardware. The device recovery time ranges from 0 to 35
> seconds. In our test pool it will take about 30 seconds to run on a
> Power8 system that with 5 breakable devices, 60 seconds to run on a
> Power9 system that with 4 breakable devices.
>
> Extend the timeout setting in the kselftest framework to 5 minutes
> to give it a chance to finish.
>
> Signed-off-by: Po-Hsu Lin 
> ---
>  tools/testing/selftests/powerpc/eeh/Makefile | 2 +-
>  tools/testing/selftests/powerpc/eeh/settings | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/powerpc/eeh/settings
>
> diff --git a/tools/testing/selftests/powerpc/eeh/Makefile 
> b/tools/testing/selftests/powerpc/eeh/Makefile
> index b397bab..ae963eb 100644
> --- a/tools/testing/selftests/powerpc/eeh/Makefile
> +++ b/tools/testing/selftests/powerpc/eeh/Makefile
> @@ -3,7 +3,7 @@ noarg:
> $(MAKE) -C ../
>
>  TEST_PROGS := eeh-basic.sh
> -TEST_FILES := eeh-functions.sh
> +TEST_FILES := eeh-functions.sh settings
>
>  top_srcdir = ../../../../..
>  include ../../lib.mk
> diff --git a/tools/testing/selftests/powerpc/eeh/settings 
> b/tools/testing/selftests/powerpc/eeh/settings
> new file mode 100644
> index 000..694d707
> --- /dev/null
> +++ b/tools/testing/selftests/powerpc/eeh/settings
> @@ -0,0 +1 @@
> +timeout=300
> --
> 2.7.4
>


[PATCHv2 1/2] selftests: pmtu.sh: use $ksft_skip for skipped return code

2020-11-09 Thread Po-Hsu Lin
This test uses return code 2 as a hard-coded skipped state, let's use
the kselftest framework skip code variable $ksft_skip instead to make
it more readable and easier to maintain.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/pmtu.sh | 64 ++---
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/tools/testing/selftests/net/pmtu.sh 
b/tools/testing/selftests/net/pmtu.sh
index 6bbf69a..fb53987 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -355,7 +355,7 @@ setup_fou_or_gue() {
encap="${3}"
 
if [ "${outer}" = "4" ]; then
-   modprobe fou || return 2
+   modprobe fou || return $ksft_skip
a_addr="${prefix4}.${a_r1}.1"
b_addr="${prefix4}.${b_r1}.1"
if [ "${inner}" = "4" ]; then
@@ -366,7 +366,7 @@ setup_fou_or_gue() {
ipproto="41"
fi
else
-   modprobe fou6 || return 2
+   modprobe fou6 || return $ksft_skip
a_addr="${prefix6}:${a_r1}::1"
b_addr="${prefix6}:${b_r1}::1"
if [ "${inner}" = "4" ]; then
@@ -380,8 +380,8 @@ setup_fou_or_gue() {
fi
fi
 
-   run_cmd ${ns_a} ip fou add port  ipproto ${ipproto} || return 2
-   run_cmd ${ns_a} ip link add ${encap}_a type ${type} ${mode} local 
${a_addr} remote ${b_addr} encap ${encap} encap-sport auto encap-dport 5556 || 
return 2
+   run_cmd ${ns_a} ip fou add port  ipproto ${ipproto} || return 
$ksft_skip
+   run_cmd ${ns_a} ip link add ${encap}_a type ${type} ${mode} local 
${a_addr} remote ${b_addr} encap ${encap} encap-sport auto encap-dport 5556 || 
return $ksft_skip
 
run_cmd ${ns_b} ip fou add port 5556 ipproto ${ipproto}
run_cmd ${ns_b} ip link add ${encap}_b type ${type} ${mode} local 
${b_addr} remote ${a_addr} encap ${encap} encap-sport auto encap-dport 
@@ -455,7 +455,7 @@ setup_ipvX_over_ipvY() {
fi
fi
 
-   run_cmd ${ns_a} ip link add ip_a type ${type} local ${a_addr} remote 
${b_addr} mode ${mode} || return 2
+   run_cmd ${ns_a} ip link add ip_a type ${type} local ${a_addr} remote 
${b_addr} mode ${mode} || return $ksft_skip
run_cmd ${ns_b} ip link add ip_b type ${type} local ${b_addr} remote 
${a_addr} mode ${mode}
 
run_cmd ${ns_a} ip link set ip_a up
@@ -713,7 +713,7 @@ setup_routing() {
 }
 
 setup_bridge() {
-   run_cmd ${ns_a} ip link add br0 type bridge || return 2
+   run_cmd ${ns_a} ip link add br0 type bridge || return $ksft_skip
run_cmd ${ns_a} ip link set br0 up
 
run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C
@@ -765,7 +765,7 @@ setup_ovs_vxlan6() {
 }
 
 setup_ovs_bridge() {
-   run_cmd ovs-vsctl add-br ovs_br0 || return 2
+   run_cmd ovs-vsctl add-br ovs_br0 || return $ksft_skip
run_cmd ip link set ovs_br0 up
 
run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C
@@ -887,7 +887,7 @@ check_pmtu_value() {
 test_pmtu_ipvX() {
family=${1}
 
-   setup namespaces routing || return 2
+   setup namespaces routing || return $ksft_skip
trace "${ns_a}"  veth_A-R1"${ns_r1}" veth_R1-A \
  "${ns_r1}" veth_R1-B"${ns_b}"  veth_B-R1 \
  "${ns_a}"  veth_A-R2"${ns_r2}" veth_R2-A \
@@ -985,11 +985,11 @@ test_pmtu_ipvX_over_vxlanY_or_geneveY_exception() {
ll_mtu=4000
 
if [ ${outer_family} -eq 4 ]; then
-   setup namespaces routing ${type}4 || return 2
+   setup namespaces routing ${type}4 || return $ksft_skip
#  IPv4 header   UDP header   VXLAN/GENEVE 
header   Ethernet header
exp_mtu=$((${ll_mtu} - 20  - 8  - 8 
  - 14))
else
-   setup namespaces routing ${type}6 || return 2
+   setup namespaces routing ${type}6 || return $ksft_skip
#  IPv6 header   UDP header   VXLAN/GENEVE 
header   Ethernet header
exp_mtu=$((${ll_mtu} - 40  - 8  - 8 
  - 14))
fi
@@ -1060,11 +1060,11 @@ 
test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception() {
ll_mtu=4000
 
if [ ${outer_family} -eq 4 ]; then
-   setup namespaces routing bridge bridged_${type}4 || return 2
+   setup namespaces routing bridge bridged_${type}4 || return 
$ksft_skip
#  IPv4 header   UDP header   VXLAN/GENEVE 
header   Ethernet header
exp_mtu=$((${ll_mtu} - 20  - 8  - 8 
  - 1

[PATCHv2 0/2] selftests: pmtu.sh: improve the test result processing

2020-11-09 Thread Po-Hsu Lin
The pmtu.sh test script treats all non-zero return code as a failure,
thus it will be marked as FAILED when some sub-test got skipped.

This patchset will:
  1. Use the kselftest framework skip code $ksft_skip to replace the
 hardcoded SKIP return code.
  2. Improve the result processing, the test will be marked as PASSED
 if nothing goes wrong and not all the tests were skipped.

Po-Hsu Lin (2):
  selftests: pmtu.sh: use $ksft_skip for skipped return code
  selftests: pmtu.sh: improve the test result processing

 tools/testing/selftests/net/pmtu.sh | 79 +
 1 file changed, 46 insertions(+), 33 deletions(-)

-- 
2.7.4



[PATCHv2 2/2] selftests: pmtu.sh: improve the test result processing

2020-11-09 Thread Po-Hsu Lin
This test will treat all non-zero return codes as failures, it will
make the pmtu.sh test script being marked as FAILED when some
sub-test got skipped.

Improve the result processing by
  * Only mark the whole test script as SKIP when all of the
sub-tests were skipped
  * If the sub-tests were either passed or skipped, the overall
result will be PASS
  * If any of them has failed with return code 1 or anything bad
happened (e.g. return code 127 for command not found), the
overall result will be FAIL

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/pmtu.sh | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/pmtu.sh 
b/tools/testing/selftests/net/pmtu.sh
index fb53987..464e31e 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -1652,7 +1652,19 @@ run_test() {
return $ret
)
ret=$?
-   [ $ret -ne 0 ] && exitcode=1
+   case $ret in
+   0)
+   all_skipped=false
+   [ $exitcode=$ksft_skip ] && exitcode=0
+   ;;
+   $ksft_skip)
+   [ $all_skipped = true ] && exitcode=$ksft_skip
+   ;;
+   *)
+   all_skipped=false
+   exitcode=1
+   ;;
+   esac
 
return $ret
 }
@@ -1786,6 +1798,7 @@ usage() {
 #
 exitcode=0
 desc=0
+all_skipped=true
 
 while getopts :ptv o
 do
-- 
2.7.4



Re: [PATCH 2/2] selftests: pmtu.sh: improve the test result processing

2020-11-09 Thread Po-Hsu Lin
On Tue, Nov 10, 2020 at 2:09 AM Jakub Kicinski  wrote:
>
> On Mon, 9 Nov 2020 11:42:33 +0800 Po-Hsu Lin wrote:
> > On Sun, Nov 8, 2020 at 7:02 AM Jakub Kicinski  wrote:
> > >
> > > On Thu,  5 Nov 2020 18:50:51 +0800 Po-Hsu Lin wrote:
> > > > This test will treat all non-zero return codes as failures, it will
> > > > make the pmtu.sh test script being marked as FAILED when some
> > > > sub-test got skipped.
> > > >
> > > > Improve the result processing by
> > > >   * Only mark the whole test script as SKIP when all of the
> > > > sub-tests were skipped
> > > >   * If the sub-tests were either passed or skipped, the overall
> > > > result will be PASS
> > > >   * If any of them has failed, the overall result will be FAIL
> > > >   * Treat other return codes (e.g. 127 for command not found) as FAIL
> > > >
> > > > Signed-off-by: Po-Hsu Lin 
> > >
> > > Patch 1 looks like a cleanup while patch 2 is more of a fix, can we
> > > separate the two and apply the former to -next and latter to 5.10?
> > > They shouldn't conflict, right?
> > >
> >
> > Hello Jakub,
> >
> > Yes the first patch is just changing return code to $ksft_skip, the
> > real fix is the second one. However the second patch was based on the
> > first one, if we want to apply them separately we might need to change
> > this $ksft_skip handling part in the second patch.
>
> Ah, I misread the situation, ksft_skip is 4, not 2, so the patch is
> more than just refactoring.
>
> > What should I do to deal with this?
> > Resend the former for -next and rebase + resend the latter (plus the
> > fix to remove case 1) for 5.10 without the former patch?
>
> Let's apply both of the patches to net-next if that's fine with you.
> Indeed detangling them is may be more effort that it's worth.

That would be great, but allow me to resend V2 to get rid of case 1 first.
Thanks!


Re: [PATCH 2/2] selftests: pmtu.sh: improve the test result processing

2020-11-08 Thread Po-Hsu Lin
On Sun, Nov 8, 2020 at 7:02 AM Jakub Kicinski  wrote:
>
> On Thu,  5 Nov 2020 18:50:51 +0800 Po-Hsu Lin wrote:
> > This test will treat all non-zero return codes as failures, it will
> > make the pmtu.sh test script being marked as FAILED when some
> > sub-test got skipped.
> >
> > Improve the result processing by
> >   * Only mark the whole test script as SKIP when all of the
> > sub-tests were skipped
> >   * If the sub-tests were either passed or skipped, the overall
> > result will be PASS
> >   * If any of them has failed, the overall result will be FAIL
> >   * Treat other return codes (e.g. 127 for command not found) as FAIL
> >
> > Signed-off-by: Po-Hsu Lin 
>
> Patch 1 looks like a cleanup while patch 2 is more of a fix, can we
> separate the two and apply the former to -next and latter to 5.10?
> They shouldn't conflict, right?
>

Hello Jakub,

Yes the first patch is just changing return code to $ksft_skip, the
real fix is the second one. However the second patch was based on the
first one, if we want to apply them separately we might need to change
this $ksft_skip handling part in the second patch.

What should I do to deal with this?
Resend the former for -next and rebase + resend the latter (plus the
fix to remove case 1) for 5.10 without the former patch?
Thanks!

> > diff --git a/tools/testing/selftests/net/pmtu.sh 
> > b/tools/testing/selftests/net/pmtu.sh
> > index fb53987..5c86fb1 100755
> > --- a/tools/testing/selftests/net/pmtu.sh
> > +++ b/tools/testing/selftests/net/pmtu.sh
> > @@ -1652,7 +1652,23 @@ run_test() {
> >   return $ret
> >   )
> >   ret=$?
> > - [ $ret -ne 0 ] && exitcode=1
> > + case $ret in
> > + 0)
> > + all_skipped=false
> > + [ $exitcode=$ksft_skip ] && exitcode=0
> > + ;;
> > + 1)
> > + all_skipped=false
> > + exitcode=1
> > + ;;
>
> Does it make sense to remove this case? The handling is identical to
> the default case *).
>

Yes you're right, we can remove this part.

> > + $ksft_skip)
> > + [ $all_skipped = true ] && exitcode=$ksft_skip
> > + ;;
> > + *)
> > + all_skipped=false
> > + exitcode=1
> > + ;;
> > + esac
> >
> >   return $ret
> >  }
> > @@ -1786,6 +1802,7 @@ usage() {
> >  #
> >  exitcode=0
> >  desc=0
> > +all_skipped=true
> >
> >  while getopts :ptv o
> >  do
>


[PATCH 1/2] selftests: pmtu.sh: use $ksft_skip for skipped return code

2020-11-05 Thread Po-Hsu Lin
This test uses return code 2 as a hard-coded skipped state, let's use
the kselftest framework skip code variable $ksft_skip instead to make
it more readable and easier to maintain.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/pmtu.sh | 64 ++---
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/tools/testing/selftests/net/pmtu.sh 
b/tools/testing/selftests/net/pmtu.sh
index 6bbf69a..fb53987 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -355,7 +355,7 @@ setup_fou_or_gue() {
encap="${3}"
 
if [ "${outer}" = "4" ]; then
-   modprobe fou || return 2
+   modprobe fou || return $ksft_skip
a_addr="${prefix4}.${a_r1}.1"
b_addr="${prefix4}.${b_r1}.1"
if [ "${inner}" = "4" ]; then
@@ -366,7 +366,7 @@ setup_fou_or_gue() {
ipproto="41"
fi
else
-   modprobe fou6 || return 2
+   modprobe fou6 || return $ksft_skip
a_addr="${prefix6}:${a_r1}::1"
b_addr="${prefix6}:${b_r1}::1"
if [ "${inner}" = "4" ]; then
@@ -380,8 +380,8 @@ setup_fou_or_gue() {
fi
fi
 
-   run_cmd ${ns_a} ip fou add port  ipproto ${ipproto} || return 2
-   run_cmd ${ns_a} ip link add ${encap}_a type ${type} ${mode} local 
${a_addr} remote ${b_addr} encap ${encap} encap-sport auto encap-dport 5556 || 
return 2
+   run_cmd ${ns_a} ip fou add port  ipproto ${ipproto} || return 
$ksft_skip
+   run_cmd ${ns_a} ip link add ${encap}_a type ${type} ${mode} local 
${a_addr} remote ${b_addr} encap ${encap} encap-sport auto encap-dport 5556 || 
return $ksft_skip
 
run_cmd ${ns_b} ip fou add port 5556 ipproto ${ipproto}
run_cmd ${ns_b} ip link add ${encap}_b type ${type} ${mode} local 
${b_addr} remote ${a_addr} encap ${encap} encap-sport auto encap-dport 
@@ -455,7 +455,7 @@ setup_ipvX_over_ipvY() {
fi
fi
 
-   run_cmd ${ns_a} ip link add ip_a type ${type} local ${a_addr} remote 
${b_addr} mode ${mode} || return 2
+   run_cmd ${ns_a} ip link add ip_a type ${type} local ${a_addr} remote 
${b_addr} mode ${mode} || return $ksft_skip
run_cmd ${ns_b} ip link add ip_b type ${type} local ${b_addr} remote 
${a_addr} mode ${mode}
 
run_cmd ${ns_a} ip link set ip_a up
@@ -713,7 +713,7 @@ setup_routing() {
 }
 
 setup_bridge() {
-   run_cmd ${ns_a} ip link add br0 type bridge || return 2
+   run_cmd ${ns_a} ip link add br0 type bridge || return $ksft_skip
run_cmd ${ns_a} ip link set br0 up
 
run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C
@@ -765,7 +765,7 @@ setup_ovs_vxlan6() {
 }
 
 setup_ovs_bridge() {
-   run_cmd ovs-vsctl add-br ovs_br0 || return 2
+   run_cmd ovs-vsctl add-br ovs_br0 || return $ksft_skip
run_cmd ip link set ovs_br0 up
 
run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C
@@ -887,7 +887,7 @@ check_pmtu_value() {
 test_pmtu_ipvX() {
family=${1}
 
-   setup namespaces routing || return 2
+   setup namespaces routing || return $ksft_skip
trace "${ns_a}"  veth_A-R1"${ns_r1}" veth_R1-A \
  "${ns_r1}" veth_R1-B"${ns_b}"  veth_B-R1 \
  "${ns_a}"  veth_A-R2"${ns_r2}" veth_R2-A \
@@ -985,11 +985,11 @@ test_pmtu_ipvX_over_vxlanY_or_geneveY_exception() {
ll_mtu=4000
 
if [ ${outer_family} -eq 4 ]; then
-   setup namespaces routing ${type}4 || return 2
+   setup namespaces routing ${type}4 || return $ksft_skip
#  IPv4 header   UDP header   VXLAN/GENEVE 
header   Ethernet header
exp_mtu=$((${ll_mtu} - 20  - 8  - 8 
  - 14))
else
-   setup namespaces routing ${type}6 || return 2
+   setup namespaces routing ${type}6 || return $ksft_skip
#  IPv6 header   UDP header   VXLAN/GENEVE 
header   Ethernet header
exp_mtu=$((${ll_mtu} - 40  - 8  - 8 
  - 14))
fi
@@ -1060,11 +1060,11 @@ 
test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception() {
ll_mtu=4000
 
if [ ${outer_family} -eq 4 ]; then
-   setup namespaces routing bridge bridged_${type}4 || return 2
+   setup namespaces routing bridge bridged_${type}4 || return 
$ksft_skip
#  IPv4 header   UDP header   VXLAN/GENEVE 
header   Ethernet header
exp_mtu=$((${ll_mtu} - 20  - 8  - 8 
  - 1

[PATCH 0/2] selftests: pmtu.sh: improve the test result processing

2020-11-05 Thread Po-Hsu Lin
The pmtu.sh test script treats all non-zero return code as a failure,
thus it will be marked as FAILED when some sub-test got skipped.

This patchset will:
  1. Use the kselftest framework skip code $ksft_skip to replace the
 hardcoded SKIP return code.
  2. Improve the result processing, the test will be marked as PASSED
 if nothing goes wrong and not all the tests were skipped.

Po-Hsu Lin (2):
  selftests: pmtu.sh: use $ksft_skip for skipped return code
  selftests: pmtu.sh: improve the test result processing

 tools/testing/selftests/net/pmtu.sh | 83 ++---
 1 file changed, 50 insertions(+), 33 deletions(-)

-- 
2.7.4



[PATCH 2/2] selftests: pmtu.sh: improve the test result processing

2020-11-05 Thread Po-Hsu Lin
This test will treat all non-zero return codes as failures, it will
make the pmtu.sh test script being marked as FAILED when some
sub-test got skipped.

Improve the result processing by
  * Only mark the whole test script as SKIP when all of the
sub-tests were skipped
  * If the sub-tests were either passed or skipped, the overall
result will be PASS
  * If any of them has failed, the overall result will be FAIL
  * Treat other return codes (e.g. 127 for command not found) as FAIL

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/pmtu.sh | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/pmtu.sh 
b/tools/testing/selftests/net/pmtu.sh
index fb53987..5c86fb1 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -1652,7 +1652,23 @@ run_test() {
return $ret
)
ret=$?
-   [ $ret -ne 0 ] && exitcode=1
+   case $ret in
+   0)
+   all_skipped=false
+   [ $exitcode=$ksft_skip ] && exitcode=0
+   ;;
+   1)
+   all_skipped=false
+   exitcode=1
+   ;;
+   $ksft_skip)
+   [ $all_skipped = true ] && exitcode=$ksft_skip
+   ;;
+   *)
+   all_skipped=false
+   exitcode=1
+   ;;
+   esac
 
return $ret
 }
@@ -1786,6 +1802,7 @@ usage() {
 #
 exitcode=0
 desc=0
+all_skipped=true
 
 while getopts :ptv o
 do
-- 
2.7.4



[PATCHv2] selftests/powerpc/eeh: disable kselftest timeout setting for eeh-basic

2020-10-22 Thread Po-Hsu Lin
The eeh-basic test got its own 60 seconds timeout (defined in commit
414f50434aa2 "selftests/eeh: Bump EEH wait time to 60s") per breakable
device.

And we have discovered that the number of breakable devices varies
on different hardware. The device recovery time ranges from 0 to 35
seconds. In our test pool it will take about 30 seconds to run on a
Power8 system that with 5 breakable devices, 60 seconds to run on a
Power9 system that with 4 breakable devices.

Extend the timeout setting in the kselftest framework to 5 minutes
to give it a chance to finish.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/powerpc/eeh/Makefile | 2 +-
 tools/testing/selftests/powerpc/eeh/settings | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/eeh/settings

diff --git a/tools/testing/selftests/powerpc/eeh/Makefile 
b/tools/testing/selftests/powerpc/eeh/Makefile
index b397bab..ae963eb 100644
--- a/tools/testing/selftests/powerpc/eeh/Makefile
+++ b/tools/testing/selftests/powerpc/eeh/Makefile
@@ -3,7 +3,7 @@ noarg:
$(MAKE) -C ../
 
 TEST_PROGS := eeh-basic.sh
-TEST_FILES := eeh-functions.sh
+TEST_FILES := eeh-functions.sh settings
 
 top_srcdir = ../../../../..
 include ../../lib.mk
diff --git a/tools/testing/selftests/powerpc/eeh/settings 
b/tools/testing/selftests/powerpc/eeh/settings
new file mode 100644
index 000..694d707
--- /dev/null
+++ b/tools/testing/selftests/powerpc/eeh/settings
@@ -0,0 +1 @@
+timeout=300
-- 
2.7.4



Re: [PATCH] selftests/powerpc/eeh: disable kselftest timeout setting for eeh-basic

2020-10-22 Thread Po-Hsu Lin
On Fri, Oct 23, 2020 at 10:07 AM Michael Ellerman  wrote:
>
> Po-Hsu Lin  writes:
> > The eeh-basic test got its own 60 seconds timeout (defined in commit
> > 414f50434aa2 "selftests/eeh: Bump EEH wait time to 60s") per breakable
> > device.
> >
> > And we have discovered that the number of breakable devices varies
> > on different hardware. The device recovery time ranges from 0 to 35
> > seconds. In our test pool it will take about 30 seconds to run on a
> > Power8 system that with 5 breakable devices, 60 seconds to run on a
> > Power9 system that with 4 breakable devices.
> >
> > Thus it's better to disable the default 45 seconds timeout setting in
> > the kselftest framework to give it a chance to finish. And let the
> > test to take care of the timeout control.
>
> I'd prefer if we still had some timeout, maybe 5 or 10 minutes? Just in
> case the test goes completely bonkers.
>
OK, let's go for 5 minutes.
Will send V2 later.
Thanks for your suggestion!

> cheers
>
> > diff --git a/tools/testing/selftests/powerpc/eeh/Makefile 
> > b/tools/testing/selftests/powerpc/eeh/Makefile
> > index b397bab..ae963eb 100644
> > --- a/tools/testing/selftests/powerpc/eeh/Makefile
> > +++ b/tools/testing/selftests/powerpc/eeh/Makefile
> > @@ -3,7 +3,7 @@ noarg:
> >   $(MAKE) -C ../
> >
> >  TEST_PROGS := eeh-basic.sh
> > -TEST_FILES := eeh-functions.sh
> > +TEST_FILES := eeh-functions.sh settings
> >
> >  top_srcdir = ../../../../..
> >  include ../../lib.mk
> > diff --git a/tools/testing/selftests/powerpc/eeh/settings 
> > b/tools/testing/selftests/powerpc/eeh/settings
> > new file mode 100644
> > index 000..e7b9417
> > --- /dev/null
> > +++ b/tools/testing/selftests/powerpc/eeh/settings
> > @@ -0,0 +1 @@
> > +timeout=0
> > --
> > 2.7.4


[PATCH] selftests/powerpc/eeh: disable kselftest timeout setting for eeh-basic

2020-10-22 Thread Po-Hsu Lin
The eeh-basic test got its own 60 seconds timeout (defined in commit
414f50434aa2 "selftests/eeh: Bump EEH wait time to 60s") per breakable
device.

And we have discovered that the number of breakable devices varies
on different hardware. The device recovery time ranges from 0 to 35
seconds. In our test pool it will take about 30 seconds to run on a
Power8 system that with 5 breakable devices, 60 seconds to run on a
Power9 system that with 4 breakable devices.

Thus it's better to disable the default 45 seconds timeout setting in
the kselftest framework to give it a chance to finish. And let the
test to take care of the timeout control.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/powerpc/eeh/Makefile | 2 +-
 tools/testing/selftests/powerpc/eeh/settings | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/eeh/settings

diff --git a/tools/testing/selftests/powerpc/eeh/Makefile 
b/tools/testing/selftests/powerpc/eeh/Makefile
index b397bab..ae963eb 100644
--- a/tools/testing/selftests/powerpc/eeh/Makefile
+++ b/tools/testing/selftests/powerpc/eeh/Makefile
@@ -3,7 +3,7 @@ noarg:
$(MAKE) -C ../
 
 TEST_PROGS := eeh-basic.sh
-TEST_FILES := eeh-functions.sh
+TEST_FILES := eeh-functions.sh settings
 
 top_srcdir = ../../../../..
 include ../../lib.mk
diff --git a/tools/testing/selftests/powerpc/eeh/settings 
b/tools/testing/selftests/powerpc/eeh/settings
new file mode 100644
index 000..e7b9417
--- /dev/null
+++ b/tools/testing/selftests/powerpc/eeh/settings
@@ -0,0 +1 @@
+timeout=0
-- 
2.7.4



[PATCHv5] selftests: rtnetlink: load fou module for kci_test_encap_fou() test

2020-10-18 Thread Po-Hsu Lin
The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
needs the fou module to work. Otherwise it will fail with:

  $ ip netns exec "$testns" ip fou add port  ipproto 47
  RTNETLINK answers: No such file or directory
  Error talking to the kernel

Add the CONFIG_NET_FOU into the config file as well. Which needs at
least to be set as a loadable module.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/config   | 1 +
 tools/testing/selftests/net/rtnetlink.sh | 5 +
 2 files changed, 6 insertions(+)

diff --git a/tools/testing/selftests/net/config 
b/tools/testing/selftests/net/config
index 4364924..4d5df8e 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -33,3 +33,4 @@ CONFIG_KALLSYMS=y
 CONFIG_TRACEPOINTS=y
 CONFIG_NET_DROP_MONITOR=m
 CONFIG_NETDEVSIM=m
+CONFIG_NET_FOU=m
diff --git a/tools/testing/selftests/net/rtnetlink.sh 
b/tools/testing/selftests/net/rtnetlink.sh
index 8a2fe6d..c9ce3df 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -520,6 +520,11 @@ kci_test_encap_fou()
return $ksft_skip
fi
 
+   if ! /sbin/modprobe -q -n fou; then
+   echo "SKIP: module fou is not found"
+   return $ksft_skip
+   fi
+   /sbin/modprobe -q fou
ip -netns "$testns" fou add port  ipproto 47 2>/dev/null
if [ $? -ne 0 ];then
echo "FAIL: can't add fou port , skipping test"
-- 
2.7.4



Re: [PATCHv4] selftests: rtnetlink: load fou module for kci_test_encap_fou() test

2020-10-18 Thread Po-Hsu Lin
On Sat, Oct 17, 2020 at 7:32 AM Jakub Kicinski  wrote:
>
> On Fri, 16 Oct 2020 12:12:11 +0800 Po-Hsu Lin wrote:
> > The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
> > needs the fou module to work. Otherwise it will fail with:
> >
> >   $ ip netns exec "$testns" ip fou add port  ipproto 47
> >   RTNETLINK answers: No such file or directory
> >   Error talking to the kernel
> >
> > Add the CONFIG_NET_FOU into the config file as well. Which needs at
> > least to be set as a loadable module.
> >
> > Signed-off-by: Po-Hsu Lin 
>
> Doesn't apply :( Could you rebase on top of:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/
Ah OK, I was using the next branch in kselftest, will resend another one.
Thanks.


[PATCHv4] selftests: rtnetlink: load fou module for kci_test_encap_fou() test

2020-10-15 Thread Po-Hsu Lin
The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
needs the fou module to work. Otherwise it will fail with:

  $ ip netns exec "$testns" ip fou add port  ipproto 47
  RTNETLINK answers: No such file or directory
  Error talking to the kernel

Add the CONFIG_NET_FOU into the config file as well. Which needs at
least to be set as a loadable module.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/config   | 1 +
 tools/testing/selftests/net/rtnetlink.sh | 5 +
 2 files changed, 6 insertions(+)

diff --git a/tools/testing/selftests/net/config 
b/tools/testing/selftests/net/config
index 3b42c06b..c5e50ab 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -31,3 +31,4 @@ CONFIG_NET_SCH_ETF=m
 CONFIG_NET_SCH_NETEM=y
 CONFIG_TEST_BLACKHOLE_DEV=m
 CONFIG_KALLSYMS=y
+CONFIG_NET_FOU=m
diff --git a/tools/testing/selftests/net/rtnetlink.sh 
b/tools/testing/selftests/net/rtnetlink.sh
index 7c38a90..6f8f159 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -520,6 +520,11 @@ kci_test_encap_fou()
return $ksft_skip
fi
 
+   if ! /sbin/modprobe -q -n fou; then
+   echo "SKIP: module fou is not found"
+   return $ksft_skip
+   fi
+   /sbin/modprobe -q fou
ip -netns "$testns" fou add port  ipproto 47 2>/dev/null
if [ $? -ne 0 ];then
echo "FAIL: can't add fou port , skipping test"
-- 
2.7.4



Re: [PATCHv3] selftests: rtnetlink: load fou module for kci_test_encap_fou() test

2020-10-12 Thread Po-Hsu Lin
On Mon, Oct 12, 2020 at 11:28 PM Jakub Kicinski  wrote:
>
> On Mon, 12 Oct 2020 13:56:15 +0800 Po-Hsu Lin wrote:
> > Is there any update on this patch?
>
> You received feedback. Don't remove modules after tests, something else
> could be using them.

Hello Jakub,
I have my feedback regarding your input [1], so I guess it's not
persuasive enough?
Thanks

[1] https://marc.info/?l=linux-kernel=159954826414645=2


Re: [PATCHv3] selftests: rtnetlink: load fou module for kci_test_encap_fou() test

2020-10-11 Thread Po-Hsu Lin
Hello,
Is there any update on this patch?
Thanks!
PHLin

On Fri, Sep 18, 2020 at 6:39 PM Po-Hsu Lin  wrote:
>
> Hello folks,
>
> any thoughts on this patch?
> It can make the test pass and reduce the failure numbers in
> kselftests, it will be great to have this applied.
>
> Thanks
> PHLin
>
>
> On Tue, Sep 8, 2020 at 2:57 PM Po-Hsu Lin  wrote:
> >
> > On Tue, Sep 8, 2020 at 4:12 AM Jakub Kicinski  wrote:
> > >
> > > On Mon,  7 Sep 2020 11:50:10 +0800 Po-Hsu Lin wrote:
> > > > The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
> > > > needs the fou module to work. Otherwise it will fail with:
> > > >
> > > >   $ ip netns exec "$testns" ip fou add port  ipproto 47
> > > >   RTNETLINK answers: No such file or directory
> > > >   Error talking to the kernel
> > > >
> > > > Add the CONFIG_NET_FOU into the config file as well. Which needs at
> > > > least to be set as a loadable module.
> > > >
> > > > Signed-off-by: Po-Hsu Lin 
> > >
> > > > diff --git a/tools/testing/selftests/net/rtnetlink.sh 
> > > > b/tools/testing/selftests/net/rtnetlink.sh
> > > > index 7c38a90..a711b3e 100755
> > > > --- a/tools/testing/selftests/net/rtnetlink.sh
> > > > +++ b/tools/testing/selftests/net/rtnetlink.sh
> > > > @@ -520,6 +520,11 @@ kci_test_encap_fou()
> > > >   return $ksft_skip
> > > >   fi
> > > >
> > > > + if ! /sbin/modprobe -q -n fou; then
> > > > + echo "SKIP: module fou is not found"
> > > > + return $ksft_skip
> > > > + fi
> > > > + /sbin/modprobe -q fou
> > > >   ip -netns "$testns" fou add port  ipproto 47 2>/dev/null
> > > >   if [ $? -ne 0 ];then
> > > >   echo "FAIL: can't add fou port , skipping test"
> > > > @@ -540,6 +545,7 @@ kci_test_encap_fou()
> > > >   return 1
> > > >   fi
> > > >
> > > > + /sbin/modprobe -q -r fou
> > >
> > > I think the common practice is to not remove the module at the end of
> > > the test. It may be used by something else than the test itself.
> > >
> > Hello Jakub,
> > Thanks for your feedback.
> >
> > For this case I think it's safe to remove the module here, as it was
> > never loaded before and thus causing this test to fail.
> > If other tests in this rtnetlink.sh need this fou module, we should be
> > able to spot those failures too, however this is the only failure as I
> > can see.
> > (pmtu.sh will need fou module to run as well, but it will be loaded there.)
> >
> > Shouldn't we insert the required module whenever the test needs it? So
> > that we can run the test itself directly, without depending on other
> > tests.
> > Also, I can see modules for tests were being unloaded in other tests as 
> > well.
> >
> > Thanks
> >
> > > >   echo "PASS: fou"
> > > >  }
> > > >
> > >


Re: [PATCHv3] selftests: rtnetlink: load fou module for kci_test_encap_fou() test

2020-09-18 Thread Po-Hsu Lin
Hello folks,

any thoughts on this patch?
It can make the test pass and reduce the failure numbers in
kselftests, it will be great to have this applied.

Thanks
PHLin


On Tue, Sep 8, 2020 at 2:57 PM Po-Hsu Lin  wrote:
>
> On Tue, Sep 8, 2020 at 4:12 AM Jakub Kicinski  wrote:
> >
> > On Mon,  7 Sep 2020 11:50:10 +0800 Po-Hsu Lin wrote:
> > > The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
> > > needs the fou module to work. Otherwise it will fail with:
> > >
> > >   $ ip netns exec "$testns" ip fou add port  ipproto 47
> > >   RTNETLINK answers: No such file or directory
> > >   Error talking to the kernel
> > >
> > > Add the CONFIG_NET_FOU into the config file as well. Which needs at
> > > least to be set as a loadable module.
> > >
> > > Signed-off-by: Po-Hsu Lin 
> >
> > > diff --git a/tools/testing/selftests/net/rtnetlink.sh 
> > > b/tools/testing/selftests/net/rtnetlink.sh
> > > index 7c38a90..a711b3e 100755
> > > --- a/tools/testing/selftests/net/rtnetlink.sh
> > > +++ b/tools/testing/selftests/net/rtnetlink.sh
> > > @@ -520,6 +520,11 @@ kci_test_encap_fou()
> > >   return $ksft_skip
> > >   fi
> > >
> > > + if ! /sbin/modprobe -q -n fou; then
> > > + echo "SKIP: module fou is not found"
> > > + return $ksft_skip
> > > + fi
> > > + /sbin/modprobe -q fou
> > >   ip -netns "$testns" fou add port  ipproto 47 2>/dev/null
> > >   if [ $? -ne 0 ];then
> > >   echo "FAIL: can't add fou port , skipping test"
> > > @@ -540,6 +545,7 @@ kci_test_encap_fou()
> > >   return 1
> > >   fi
> > >
> > > + /sbin/modprobe -q -r fou
> >
> > I think the common practice is to not remove the module at the end of
> > the test. It may be used by something else than the test itself.
> >
> Hello Jakub,
> Thanks for your feedback.
>
> For this case I think it's safe to remove the module here, as it was
> never loaded before and thus causing this test to fail.
> If other tests in this rtnetlink.sh need this fou module, we should be
> able to spot those failures too, however this is the only failure as I
> can see.
> (pmtu.sh will need fou module to run as well, but it will be loaded there.)
>
> Shouldn't we insert the required module whenever the test needs it? So
> that we can run the test itself directly, without depending on other
> tests.
> Also, I can see modules for tests were being unloaded in other tests as well.
>
> Thanks
>
> > >   echo "PASS: fou"
> > >  }
> > >
> >


Re: [PATCHv3] selftests: rtnetlink: load fou module for kci_test_encap_fou() test

2020-09-08 Thread Po-Hsu Lin
On Tue, Sep 8, 2020 at 4:12 AM Jakub Kicinski  wrote:
>
> On Mon,  7 Sep 2020 11:50:10 +0800 Po-Hsu Lin wrote:
> > The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
> > needs the fou module to work. Otherwise it will fail with:
> >
> >   $ ip netns exec "$testns" ip fou add port  ipproto 47
> >   RTNETLINK answers: No such file or directory
> >   Error talking to the kernel
> >
> > Add the CONFIG_NET_FOU into the config file as well. Which needs at
> > least to be set as a loadable module.
> >
> > Signed-off-by: Po-Hsu Lin 
>
> > diff --git a/tools/testing/selftests/net/rtnetlink.sh 
> > b/tools/testing/selftests/net/rtnetlink.sh
> > index 7c38a90..a711b3e 100755
> > --- a/tools/testing/selftests/net/rtnetlink.sh
> > +++ b/tools/testing/selftests/net/rtnetlink.sh
> > @@ -520,6 +520,11 @@ kci_test_encap_fou()
> >   return $ksft_skip
> >   fi
> >
> > + if ! /sbin/modprobe -q -n fou; then
> > + echo "SKIP: module fou is not found"
> > + return $ksft_skip
> > + fi
> > + /sbin/modprobe -q fou
> >   ip -netns "$testns" fou add port  ipproto 47 2>/dev/null
> >   if [ $? -ne 0 ];then
> >   echo "FAIL: can't add fou port , skipping test"
> > @@ -540,6 +545,7 @@ kci_test_encap_fou()
> >   return 1
> >   fi
> >
> > + /sbin/modprobe -q -r fou
>
> I think the common practice is to not remove the module at the end of
> the test. It may be used by something else than the test itself.
>
Hello Jakub,
Thanks for your feedback.

For this case I think it's safe to remove the module here, as it was
never loaded before and thus causing this test to fail.
If other tests in this rtnetlink.sh need this fou module, we should be
able to spot those failures too, however this is the only failure as I
can see.
(pmtu.sh will need fou module to run as well, but it will be loaded there.)

Shouldn't we insert the required module whenever the test needs it? So
that we can run the test itself directly, without depending on other
tests.
Also, I can see modules for tests were being unloaded in other tests as well.

Thanks

> >   echo "PASS: fou"
> >  }
> >
>


[PATCHv3] selftests: rtnetlink: load fou module for kci_test_encap_fou() test

2020-09-06 Thread Po-Hsu Lin
The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
needs the fou module to work. Otherwise it will fail with:

  $ ip netns exec "$testns" ip fou add port  ipproto 47
  RTNETLINK answers: No such file or directory
  Error talking to the kernel

Add the CONFIG_NET_FOU into the config file as well. Which needs at
least to be set as a loadable module.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/config   | 1 +
 tools/testing/selftests/net/rtnetlink.sh | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/tools/testing/selftests/net/config 
b/tools/testing/selftests/net/config
index 3b42c06b..c5e50ab 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -31,3 +31,4 @@ CONFIG_NET_SCH_ETF=m
 CONFIG_NET_SCH_NETEM=y
 CONFIG_TEST_BLACKHOLE_DEV=m
 CONFIG_KALLSYMS=y
+CONFIG_NET_FOU=m
diff --git a/tools/testing/selftests/net/rtnetlink.sh 
b/tools/testing/selftests/net/rtnetlink.sh
index 7c38a90..a711b3e 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -520,6 +520,11 @@ kci_test_encap_fou()
return $ksft_skip
fi
 
+   if ! /sbin/modprobe -q -n fou; then
+   echo "SKIP: module fou is not found"
+   return $ksft_skip
+   fi
+   /sbin/modprobe -q fou
ip -netns "$testns" fou add port  ipproto 47 2>/dev/null
if [ $? -ne 0 ];then
echo "FAIL: can't add fou port , skipping test"
@@ -540,6 +545,7 @@ kci_test_encap_fou()
return 1
fi
 
+   /sbin/modprobe -q -r fou
echo "PASS: fou"
 }
 
-- 
2.7.4



Re: [PATCHv2] selftests: rtnetlink: load fou module for kci_test_encap_fou()

2020-09-04 Thread Po-Hsu Lin
Hello David,

do you need more information for this V2 patch?

Thank you
PHLin

On Mon, Aug 17, 2020 at 10:53 AM Po-Hsu Lin  wrote:
>
> The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
> needs the fou module to work. Otherwise it will fail with:
>
>   $ ip netns exec "$testns" ip fou add port  ipproto 47
>   RTNETLINK answers: No such file or directory
>   Error talking to the kernel
>
> Add the CONFIG_NET_FOU into the config file as well. Which needs at
> least to be set as a loadable module.
>
> Signed-off-by: Po-Hsu Lin 
> ---
>  tools/testing/selftests/net/config   | 1 +
>  tools/testing/selftests/net/rtnetlink.sh | 6 ++
>  2 files changed, 7 insertions(+)
>
> diff --git a/tools/testing/selftests/net/config 
> b/tools/testing/selftests/net/config
> index 3b42c06b..96d2763 100644
> --- a/tools/testing/selftests/net/config
> +++ b/tools/testing/selftests/net/config
> @@ -31,3 +31,4 @@ CONFIG_NET_SCH_ETF=m
>  CONFIG_NET_SCH_NETEM=y
>  CONFIG_TEST_BLACKHOLE_DEV=m
>  CONFIG_KALLSYMS=y
> +CONFIG_NET_FOU=m
> diff --git a/tools/testing/selftests/net/rtnetlink.sh 
> b/tools/testing/selftests/net/rtnetlink.sh
> index bdbf4b3..7931b65 100755
> --- a/tools/testing/selftests/net/rtnetlink.sh
> +++ b/tools/testing/selftests/net/rtnetlink.sh
> @@ -521,6 +521,11 @@ kci_test_encap_fou()
> return $ksft_skip
> fi
>
> +   if ! /sbin/modprobe -q -n fou; then
> +   echo "SKIP: module fou is not found"
> +   return $ksft_skip
> +   fi
> +   /sbin/modprobe -q fou
> ip -netns "$testns" fou add port  ipproto 47 2>/dev/null
> if [ $? -ne 0 ];then
> echo "FAIL: can't add fou port , skipping test"
> @@ -541,6 +546,7 @@ kci_test_encap_fou()
> return 1
> fi
>
> +   /sbin/modprobe -q -r fou
> echo "PASS: fou"
>  }
>
> --
> 2.7.4
>


[PATCH] selftests/net: improve descriptions for XFAIL cases in psock_snd.sh

2020-09-01 Thread Po-Hsu Lin
Before changing this it's a bit confusing to read test output:
  raw csum_off with bad offset (fails)
  ./psock_snd: write: Invalid argument

Change "fails" in the test case description to "expected to fail", so
that the test output can be more understandable.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/psock_snd.sh | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/net/psock_snd.sh 
b/tools/testing/selftests/net/psock_snd.sh
index 6331d91..170be65 100755
--- a/tools/testing/selftests/net/psock_snd.sh
+++ b/tools/testing/selftests/net/psock_snd.sh
@@ -45,7 +45,7 @@ echo "raw vnet hdr"
 echo "raw csum_off"
 ./in_netns.sh ./psock_snd -v -c
 
-echo "raw csum_off with bad offset (fails)"
+echo "raw csum_off with bad offset (expected to fail)"
 (! ./in_netns.sh ./psock_snd -v -c -C)
 
 
@@ -57,7 +57,7 @@ echo "raw min size"
 echo "raw mtu size"
 ./in_netns.sh ./psock_snd -l "${mss}"
 
-echo "raw mtu size + 1 (fails)"
+echo "raw mtu size + 1 (expected to fail)"
 (! ./in_netns.sh ./psock_snd -l "${mss_exceeds}")
 
 # fails due to ARPHRD_ETHER check in packet_extra_vlan_len_allowed
@@ -65,19 +65,19 @@ echo "raw mtu size + 1 (fails)"
 # echo "raw vlan mtu size"
 # ./in_netns.sh ./psock_snd -V -l "${mss}"
 
-echo "raw vlan mtu size + 1 (fails)"
+echo "raw vlan mtu size + 1 (expected to fail)"
 (! ./in_netns.sh ./psock_snd -V -l "${mss_exceeds}")
 
 echo "dgram mtu size"
 ./in_netns.sh ./psock_snd -d -l "${mss}"
 
-echo "dgram mtu size + 1 (fails)"
+echo "dgram mtu size + 1 (expected to fail)"
 (! ./in_netns.sh ./psock_snd -d -l "${mss_exceeds}")
 
-echo "raw truncate hlen (fails: does not arrive)"
+echo "raw truncate hlen (expected to fail: does not arrive)"
 (! ./in_netns.sh ./psock_snd -t "$((${vnet_hlen} + ${eth_hlen}))")
 
-echo "raw truncate hlen - 1 (fails: EINVAL)"
+echo "raw truncate hlen - 1 (expected to fail: EINVAL)"
 (! ./in_netns.sh ./psock_snd -t "$((${vnet_hlen} + ${eth_hlen} - 1))")
 
 
@@ -86,13 +86,13 @@ echo "raw truncate hlen - 1 (fails: EINVAL)"
 echo "raw gso min size"
 ./in_netns.sh ./psock_snd -v -c -g -l "${mss_exceeds}"
 
-echo "raw gso min size - 1 (fails)"
+echo "raw gso min size - 1 (expected to fail)"
 (! ./in_netns.sh ./psock_snd -v -c -g -l "${mss}")
 
 echo "raw gso max size"
 ./in_netns.sh ./psock_snd -v -c -g -l "${max_mss}"
 
-echo "raw gso max size + 1 (fails)"
+echo "raw gso max size + 1 (expected to fail)"
 (! ./in_netns.sh ./psock_snd -v -c -g -l "${max_mss_exceeds}")
 
 echo "OK. All tests passed"
-- 
2.7.4



Re: [PATCH] selftests: rtnetlink: load fou module for kci_test_encap_fou()

2020-08-16 Thread Po-Hsu Lin
On Sat, Aug 15, 2020 at 7:43 AM David Miller  wrote:
>
> From: Po-Hsu Lin 
> Date: Thu, 13 Aug 2020 12:44:22 +0800
>
> > diff --git a/tools/testing/selftests/net/config 
> > b/tools/testing/selftests/net/config
> > index 3b42c06b..96d2763 100644
> > --- a/tools/testing/selftests/net/config
> > +++ b/tools/testing/selftests/net/config
> > @@ -31,3 +31,4 @@ CONFIG_NET_SCH_ETF=m
> >  CONFIG_NET_SCH_NETEM=y
> >  CONFIG_TEST_BLACKHOLE_DEV=m
> >  CONFIG_KALLSYMS=y
> > +CONFIG_NET_FOU
>
> You need to assign it a value, not just add it to the file by itself.
Oops!
Patch re-submitted.
Thanks for catching this.


[PATCHv2] selftests: rtnetlink: load fou module for kci_test_encap_fou()

2020-08-16 Thread Po-Hsu Lin
The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
needs the fou module to work. Otherwise it will fail with:

  $ ip netns exec "$testns" ip fou add port  ipproto 47
  RTNETLINK answers: No such file or directory
  Error talking to the kernel

Add the CONFIG_NET_FOU into the config file as well. Which needs at
least to be set as a loadable module.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/config   | 1 +
 tools/testing/selftests/net/rtnetlink.sh | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/tools/testing/selftests/net/config 
b/tools/testing/selftests/net/config
index 3b42c06b..96d2763 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -31,3 +31,4 @@ CONFIG_NET_SCH_ETF=m
 CONFIG_NET_SCH_NETEM=y
 CONFIG_TEST_BLACKHOLE_DEV=m
 CONFIG_KALLSYMS=y
+CONFIG_NET_FOU=m
diff --git a/tools/testing/selftests/net/rtnetlink.sh 
b/tools/testing/selftests/net/rtnetlink.sh
index bdbf4b3..7931b65 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -521,6 +521,11 @@ kci_test_encap_fou()
return $ksft_skip
fi
 
+   if ! /sbin/modprobe -q -n fou; then
+   echo "SKIP: module fou is not found"
+   return $ksft_skip
+   fi
+   /sbin/modprobe -q fou
ip -netns "$testns" fou add port  ipproto 47 2>/dev/null
if [ $? -ne 0 ];then
echo "FAIL: can't add fou port , skipping test"
@@ -541,6 +546,7 @@ kci_test_encap_fou()
return 1
fi
 
+   /sbin/modprobe -q -r fou
echo "PASS: fou"
 }
 
-- 
2.7.4



[PATCH] selftests: rtnetlink: load fou module for kci_test_encap_fou()

2020-08-12 Thread Po-Hsu Lin
The kci_test_encap_fou() test from kci_test_encap() in rtnetlink.sh
needs the fou module to work. Otherwise it will fail with:

  $ ip netns exec "$testns" ip fou add port  ipproto 47
  RTNETLINK answers: No such file or directory
  Error talking to the kernel

Add the CONFIG_NET_FOU into the config file as well.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/config   | 1 +
 tools/testing/selftests/net/rtnetlink.sh | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/tools/testing/selftests/net/config 
b/tools/testing/selftests/net/config
index 3b42c06b..96d2763 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -31,3 +31,4 @@ CONFIG_NET_SCH_ETF=m
 CONFIG_NET_SCH_NETEM=y
 CONFIG_TEST_BLACKHOLE_DEV=m
 CONFIG_KALLSYMS=y
+CONFIG_NET_FOU
diff --git a/tools/testing/selftests/net/rtnetlink.sh 
b/tools/testing/selftests/net/rtnetlink.sh
index bdbf4b3..7931b65 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -521,6 +521,11 @@ kci_test_encap_fou()
return $ksft_skip
fi
 
+   if ! /sbin/modprobe -q -n fou; then
+   echo "SKIP: module fou is not found"
+   return $ksft_skip
+   fi
+   /sbin/modprobe -q fou
ip -netns "$testns" fou add port  ipproto 47 2>/dev/null
if [ $? -ne 0 ];then
echo "FAIL: can't add fou port , skipping test"
@@ -541,6 +546,7 @@ kci_test_encap_fou()
return 1
fi
 
+   /sbin/modprobe -q -r fou
echo "PASS: fou"
 }
 
-- 
2.7.4



[PATCH 1/2] selftests: rtnetlink: correct the final return value for the test

2020-08-04 Thread Po-Hsu Lin
The return value "ret" will be reset to 0 from the beginning of each
sub-test in rtnetlink.sh, therefore this test will always pass if the
last sub-test has passed:
$ sudo ./rtnetlink.sh
PASS: policy routing
PASS: route get
PASS: preferred_lft addresses have expired
PASS: promote_secondaries complete
PASS: tc htb hierarchy
PASS: gre tunnel endpoint
PASS: gretap
PASS: ip6gretap
PASS: erspan
PASS: ip6erspan
PASS: bridge setup
PASS: ipv6 addrlabel
PASS: set ifalias a39ee707-e36b-41d3-802f-63179ed4d580 for test-dummy0
PASS: vrf
PASS: vxlan
FAIL: can't add fou port , skipping test
PASS: macsec
PASS: ipsec
3,7c3,7
< sa[0]spi=0x0009 proto=0x32 salt=0x64636261 crypt=1
< sa[0]key=0x31323334 35363738 39303132 33343536
< sa[1] rx ipaddr=0x   c0a87b03
< sa[1]spi=0x0009 proto=0x32 salt=0x64636261 crypt=1
< sa[1]key=0x31323334 35363738 39303132 33343536
---
> sa[0]spi=0x0009 proto=0x32 salt=0x61626364 crypt=1
> sa[0]key=0x34333231 38373635 32313039 36353433
> sa[1] rx ipaddr=0x   037ba8c0
> sa[1]spi=0x0009 proto=0x32 salt=0x61626364 crypt=1
> sa[1]key=0x34333231 38373635 32313039 36353433
FAIL: ipsec_offload incorrect driver data
FAIL: ipsec_offload
PASS: bridge fdb get
PASS: neigh get
$ echo $?
0

Make "ret" become a local variable for all sub-tests.
Also, check the sub-test results in kci_test_rtnl() and return the
final result for this test.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/rtnetlink.sh | 65 +---
 1 file changed, 43 insertions(+), 22 deletions(-)

diff --git a/tools/testing/selftests/net/rtnetlink.sh 
b/tools/testing/selftests/net/rtnetlink.sh
index bdbf4b3..9db66be 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -5,7 +5,6 @@
 # set -e
 
 devdummy="test-dummy0"
-ret=0
 
 # Kselftest framework requirement - SKIP code is 4.
 ksft_skip=4
@@ -66,7 +65,7 @@ kci_test_bridge()
devbr="test-br0"
vlandev="testbr-vlan1"
 
-   ret=0
+   local ret=0
ip link add name "$devbr" type bridge
check_err $?
 
@@ -113,7 +112,7 @@ kci_test_gre()
rem=10.42.42.1
loc=10.0.0.1
 
-   ret=0
+   local ret=0
ip tunnel add $gredev mode gre remote $rem local $loc ttl 1
check_err $?
ip link set $gredev up
@@ -149,7 +148,7 @@ kci_test_gre()
 kci_test_tc()
 {
dev=lo
-   ret=0
+   local ret=0
 
tc qdisc add dev "$dev" root handle 1: htb
check_err $?
@@ -184,7 +183,7 @@ kci_test_tc()
 
 kci_test_polrouting()
 {
-   ret=0
+   local ret=0
ip rule add fwmark 1 lookup 100
check_err $?
ip route add local 0.0.0.0/0 dev lo table 100
@@ -207,7 +206,7 @@ kci_test_route_get()
 {
local hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
 
-   ret=0
+   local ret=0
 
ip route get 127.0.0.1 > /dev/null
check_err $?
@@ -290,7 +289,7 @@ kci_test_promote_secondaries()
 
 kci_test_addrlabel()
 {
-   ret=0
+   local ret=0
 
ip addrlabel add prefix dead::/64 dev lo label 1
check_err $?
@@ -330,7 +329,7 @@ kci_test_addrlabel()
 
 kci_test_ifalias()
 {
-   ret=0
+   local ret=0
namewant=$(uuidgen)
syspathname="/sys/class/net/$devdummy/ifalias"
 
@@ -385,7 +384,7 @@ kci_test_ifalias()
 kci_test_vrf()
 {
vrfname="test-vrf"
-   ret=0
+   local ret=0
 
ip link show type vrf 2>/dev/null
if [ $? -ne 0 ]; then
@@ -425,7 +424,7 @@ kci_test_vrf()
 
 kci_test_encap_vxlan()
 {
-   ret=0
+   local ret=0
vxlan="test-vxlan0"
vlan="test-vlan0"
testns="$1"
@@ -511,7 +510,7 @@ kci_test_encap_vxlan()
 
 kci_test_encap_fou()
 {
-   ret=0
+   local ret=0
name="test-fou"
testns="$1"
 
@@ -548,7 +547,7 @@ kci_test_encap_fou()
 kci_test_encap()
 {
testns="testns"
-   ret=0
+   local ret=0
 
ip netns add "$testns"
if [ $? -ne 0 ]; then
@@ -573,7 +572,7 @@ kci_test_encap()
 kci_test_macsec()
 {
msname="test_macsec0"
-   ret=0
+   local ret=0
 
ip macsec help 2>&1 | grep -q "^Usage: ip macsec"
if [ $? -ne 0 ]; then
@@ -631,7 +630,7 @@ kci_test_macsec()
 #---
 kci_test_ipsec()
 {
-   ret=0
+   local ret=0
algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 
128"
srcip=192.168.123.1
dstip=192.168.123.2
@@ -731,7 +730,7

[PATCH 2/2] selftests: rtnetlink: make kci_test_encap() return sub-test result

2020-08-04 Thread Po-Hsu Lin
kci_test_encap() is actually composed by two different sub-tests,
kci_test_encap_vxlan() and kci_test_encap_fou()

Therefore we should check the test result of these two in
kci_test_encap() to let the script be aware of the pass / fail status.
Otherwise it will generate false-negative result like below:
$ sudo ./test.sh
PASS: policy routing
PASS: route get
PASS: preferred_lft addresses have expired
PASS: promote_secondaries complete
PASS: tc htb hierarchy
PASS: gre tunnel endpoint
PASS: gretap
PASS: ip6gretap
PASS: erspan
PASS: ip6erspan
PASS: bridge setup
PASS: ipv6 addrlabel
PASS: set ifalias 5b193daf-0a08-46d7-af2c-e7aadd422ded for test-dummy0
PASS: vrf
PASS: vxlan
FAIL: can't add fou port , skipping test
PASS: macsec
PASS: bridge fdb get
PASS: neigh get
$ echo $?
0

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/rtnetlink.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/net/rtnetlink.sh 
b/tools/testing/selftests/net/rtnetlink.sh
index 9db66be..7c38a90 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -564,9 +564,12 @@ kci_test_encap()
check_err $?
 
kci_test_encap_vxlan "$testns"
+   check_err $?
kci_test_encap_fou "$testns"
+   check_err $?
 
ip netns del "$testns"
+   return $ret
 }
 
 kci_test_macsec()
-- 
2.7.4



[PATCH 0/2] selftests: rtnetlink: Fix for false-negative return values

2020-08-04 Thread Po-Hsu Lin
This patchset will address the false-negative return value issue
caused by the following:
  1. The return value "ret" in this script will be reset to 0 from
 the beginning of each sub-test in rtnetlink.sh, therefore this
 rtnetlink test will always pass if the last sub-test has passed.
  2. The test result from two sub-tests in kci_test_encap() were not
 being processed, thus they will not affect the final test result
 of this test.


Po-Hsu Lin (2):
  selftests: rtnetlink: correct the final return value for the test
  selftests: rtnetlink: make kci_test_encap() return sub-test result

 tools/testing/selftests/net/rtnetlink.sh | 68 +---
 1 file changed, 46 insertions(+), 22 deletions(-)

-- 
2.7.4



Re: [PATCHv3] selftests/timers: Turn off timeout setting

2020-07-23 Thread Po-Hsu Lin
(Adding Shuah's linuxfoundation mail)
Hello,
do you need more changes / tests for this test?

Thanks!
Po-Hsu

On Wed, Mar 18, 2020 at 10:42 AM Po-Hsu Lin  wrote:
>
> The following 4 tests in timers can take longer than the default 45
> seconds that added in commit 852c8cbf34d3 ("selftests/kselftest/runner.sh:
> Add 45 second timeout per test") to run:
>   * nsleep-lat - 2m7.350s
>   * set-timer-lat - 2m0.66s
>   * inconsistency-check - 1m45.074s
>   * raw_skew - 2m0.013s
>
> Thus they will be marked as failed with the current 45s setting:
>   not ok 3 selftests: timers: nsleep-lat # TIMEOUT
>   not ok 4 selftests: timers: set-timer-lat # TIMEOUT
>   not ok 6 selftests: timers: inconsistency-check # TIMEOUT
>   not ok 7 selftests: timers: raw_skew # TIMEOUT
>
> Disable the timeout setting for timers can make these tests finish
> properly:
>   ok 3 selftests: timers: nsleep-lat
>   ok 4 selftests: timers: set-timer-lat
>   ok 6 selftests: timers: inconsistency-check
>   ok 7 selftests: timers: raw_skew
>
> https://bugs.launchpad.net/bugs/1864626
> Fixes: 852c8cbf34d3 ("selftests/kselftest/runner.sh: Add 45 second timeout 
> per test")
> Signed-off-by: Po-Hsu Lin 
> ---
>  tools/testing/selftests/timers/Makefile | 1 +
>  tools/testing/selftests/timers/settings | 1 +
>  2 files changed, 2 insertions(+)
>  create mode 100644 tools/testing/selftests/timers/settings
>
> diff --git a/tools/testing/selftests/timers/Makefile 
> b/tools/testing/selftests/timers/Makefile
> index 7656c7c..0e73a16 100644
> --- a/tools/testing/selftests/timers/Makefile
> +++ b/tools/testing/selftests/timers/Makefile
> @@ -13,6 +13,7 @@ DESTRUCTIVE_TESTS = alarmtimer-suspend valid-adjtimex 
> adjtick change_skew \
>
>  TEST_GEN_PROGS_EXTENDED = $(DESTRUCTIVE_TESTS)
>
> +TEST_FILES := settings
>
>  include ../lib.mk
>
> diff --git a/tools/testing/selftests/timers/settings 
> b/tools/testing/selftests/timers/settings
> new file mode 100644
> index 000..e7b9417
> --- /dev/null
> +++ b/tools/testing/selftests/timers/settings
> @@ -0,0 +1 @@
> +timeout=0
> --
> 2.7.4
>


Re: [PATCH] selftests/ftrace: mark irqsoff_tracer.tc test as unresolved if the test module does not exist

2020-05-05 Thread Po-Hsu Lin
On Tue, May 5, 2020 at 9:09 PM Steven Rostedt  wrote:
>
>
> You keep forgetting to Cc Shuah's other email.
Thanks!
I got the recipients list from the get_mainter.pl.

>
> On Tue,  5 May 2020 18:14:45 +0800
> Po-Hsu Lin  wrote:
>
> > The UNRESOLVED state is much more apporiate than the UNSUPPORTED state
> > for the absence of the test module, as it matches "test was set up
> > incorrectly" situation in the README file.
> >
> > A possible scenario is that the function was enabled (supported by the
> > kernel) but the module was not installed properly, in this case we
> > cannot call this as UNSUPPORTED.
> >
> > This change also make it consistent with other module-related tests
> > in ftrace.
>
> Acked-by: Steven Rostedt (VMware) 
>
> Shuah,
>
> Can you take this after Masami gives his ack (if he does that is).
>
> Thanks,
>
> -- Steve
>
> >
> > Signed-off-by: Po-Hsu Lin 
> > ---
> >  .../testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc | 9 
> > -
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git 
> > a/tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc 
> > b/tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc
> > index cbd1743..2b82c80e 100644
> > --- a/tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc
> > @@ -17,7 +17,14 @@ unsup() { #msg
> >  exit_unsupported
> >  }
> >
> > -modprobe $MOD || unsup "$MOD module not available"
> > +unres() { #msg
> > +reset_tracer
> > +rmmod $MOD || true
> > +echo $1
> > +exit_unresolved
> > +}
> > +
> > +modprobe $MOD || unres "$MOD module not available"
> >  rmmod $MOD
> >
> >  grep -q "preemptoff" available_tracers || unsup "preemptoff tracer not 
> > enabled"
>


[PATCH] selftests/ftrace: mark irqsoff_tracer.tc test as unresolved if the test module does not exist

2020-05-05 Thread Po-Hsu Lin
The UNRESOLVED state is much more apporiate than the UNSUPPORTED state
for the absence of the test module, as it matches "test was set up
incorrectly" situation in the README file.

A possible scenario is that the function was enabled (supported by the
kernel) but the module was not installed properly, in this case we
cannot call this as UNSUPPORTED.

This change also make it consistent with other module-related tests
in ftrace.

Signed-off-by: Po-Hsu Lin 
---
 .../testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc 
b/tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc
index cbd1743..2b82c80e 100644
--- a/tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc
+++ b/tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc
@@ -17,7 +17,14 @@ unsup() { #msg
 exit_unsupported
 }
 
-modprobe $MOD || unsup "$MOD module not available"
+unres() { #msg
+reset_tracer
+rmmod $MOD || true
+echo $1
+exit_unresolved
+}
+
+modprobe $MOD || unres "$MOD module not available"
 rmmod $MOD
 
 grep -q "preemptoff" available_tracers || unsup "preemptoff tracer not enabled"
-- 
2.7.4


Re: [PATCH] selftests/ftrace: treat module requirement unmet situation as unsupported

2020-05-04 Thread Po-Hsu Lin
On Fri, May 1, 2020 at 9:59 AM Masami Hiramatsu  wrote:
>
> Hi,
>
> On Wed, 29 Apr 2020 17:50:44 +0800
> Po-Hsu Lin  wrote:
>
> > When the required module for the test does not exist, use
> > exit_unsupported instead of exit_unresolved to indicate this test is
> > not supported.
>
> Hmm, this doesn't mean "the function is not supported" but
> "we can not resolve this because of the environmental issue".
> For example, if you forgot to install the modules, but the
> function itself is enabled, that can not be tested, but the
> system supports that feature.
>
> >
> > By doing this we can make test behaviour in sync with the
> > irqsoff_tracer.tc test in preemptirq, which is also treating module
> > existence in this way. Moreover, the test won't exit with a non-zero
> > return value if the module does not exist.
>
> It is OK to return zero even if the result is "unresolved", but
> I don't want to change the result of each test cases, because
> it clarify that you must install modules correctly, instead of
> enabling the feature.

Hello Masami,

With Alan Maguire's recent commit b730d668138c ("ftrace/selftest: make
unresolved cases cause failure if --fail-unresolved set") landed on
the tree.
I think this unresolved return value issue is all good here.

It is indeed a good question to brainstorm with about how to
distinguish a not enabled / enabled but not working feature.
I will fix the irqsoff_tracer.tc test here to make them consistent first.

Thank you for your feedback.
Po-Hsu

>
> And OK, I found irqsoff_tracer.tc IS incorrect. It should be fixed to
> return UNRESOLVED if there is no test module.
>
> If you still think UNRESOLVED is unneeded, please propose the patch
> which removes all UNRESOLVED related code. That can start another
> discussion.
>
> Thank you,
>
>
> >
> > Fixes: 646f01ccdd59 ("ftrace/selftest: Add tests to test 
> > register_ftrace_direct()")
> > Fixes: 4d23e9b4fd2e ("selftests/ftrace: Add trace_printk sample module 
> > test")
> > Fixes: 7bc026d6c032 ("selftests/ftrace: Add function filter on module 
> > testcase")
> > Fixes: af2a0750f374 ("selftests/ftrace: Improve kprobe on module testcase 
> > to load/unload module")
> > Signed-off-by: Po-Hsu Lin 
> > ---
> >  tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc  | 2 +-
> >  tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc  | 2 +-
> >  tools/testing/selftests/ftrace/test.d/event/trace_printk.tc| 2 +-
> >  tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc | 2 +-
> >  tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc  | 2 +-
> >  5 files changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc 
> > b/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc
> > index d75a869..3d6189e 100644
> > --- a/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc
> > @@ -5,7 +5,7 @@
> >  rmmod ftrace-direct ||:
> >  if ! modprobe ftrace-direct ; then
> >echo "No ftrace-direct sample module - please make 
> > CONFIG_SAMPLE_FTRACE_DIRECT=m"
> > -  exit_unresolved;
> > +  exit_unsupported;
> >  fi
> >
> >  echo "Let the module run a little"
> > diff --git a/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc 
> > b/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
> > index 801ecb6..3d0e3ca 100644
> > --- a/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
> > @@ -5,7 +5,7 @@
> >  rmmod ftrace-direct ||:
> >  if ! modprobe ftrace-direct ; then
> >echo "No ftrace-direct sample module - please build with 
> > CONFIG_SAMPLE_FTRACE_DIRECT=m"
> > -  exit_unresolved;
> > +  exit_unsupported;
> >  fi
> >
> >  if [ ! -f kprobe_events ]; then
> > diff --git a/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc 
> > b/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
> > index b02550b..dd8b10d 100644
> > --- a/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
> > @@ -5,7 +5,7 @@
> >  rmmod trace-printk ||:
> >  if ! modprobe trace-printk ; then
> >echo "No trace-printk sample module - please make 
> > CONFIG_SAMPLE_TRACE_PRINTK=m"
> > -  exi

Re: [PATCH] selftests/ftrace: treat module requirement unmet situation as unsupported

2020-04-29 Thread Po-Hsu Lin
On Thu, Apr 30, 2020 at 12:29 AM Steven Rostedt  wrote:
>
> On Wed, 29 Apr 2020 17:50:44 +0800
> Po-Hsu Lin  wrote:
>
> > When the required module for the test does not exist, use
> > exit_unsupported instead of exit_unresolved to indicate this test is
> > not supported.
> >
> > By doing this we can make test behaviour in sync with the
> > irqsoff_tracer.tc test in preemptirq, which is also treating module
> > existence in this way. Moreover, the test won't exit with a non-zero
> > return value if the module does not exist.
> >
> > Fixes: 646f01ccdd59 ("ftrace/selftest: Add tests to test 
> > register_ftrace_direct()")
> > Fixes: 4d23e9b4fd2e ("selftests/ftrace: Add trace_printk sample module 
> > test")
> > Fixes: 7bc026d6c032 ("selftests/ftrace: Add function filter on module 
> > testcase")
> > Fixes: af2a0750f374 ("selftests/ftrace: Improve kprobe on module testcase 
> > to load/unload module")
>
> I don't think this deserves the Fixes tags.
Hello Steven,

OK I will remove these Fixes tags and resubmit V2 if Masami agrees
with this change.

>
> > Signed-off-by: Po-Hsu Lin 
> > ---
> >  tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc  | 2 +-
> >  tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc  | 2 +-
> >  tools/testing/selftests/ftrace/test.d/event/trace_printk.tc| 2 +-
> >  tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc | 2 +-
> >  tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc  | 2 +-
>
> I'm fine with these changes if Masami is. But it is Masami's call as his
> infrastructure is more sensitive to the return calls than mine. I just run
> the test and see what passes. I don't actually look at the return codes.
Another thing to note is that this will also change the "# of
unresolved" and "# of unsupported" in the summary at the end of the
test report.

Thanks
Po-Hsu
>
> -- Steve
>
>
> >  5 files changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc 
> > b/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc
> > index d75a869..3d6189e 100644
> > --- a/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc
> > @@ -5,7 +5,7 @@
> >  rmmod ftrace-direct ||:
> >  if ! modprobe ftrace-direct ; then
> >echo "No ftrace-direct sample module - please make 
> > CONFIG_SAMPLE_FTRACE_DIRECT=m"
> > -  exit_unresolved;
> > +  exit_unsupported;
> >  fi
> >
> >  echo "Let the module run a little"
> > diff --git a/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc 
> > b/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
> > index 801ecb6..3d0e3ca 100644
> > --- a/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
> > @@ -5,7 +5,7 @@
> >  rmmod ftrace-direct ||:
> >  if ! modprobe ftrace-direct ; then
> >echo "No ftrace-direct sample module - please build with 
> > CONFIG_SAMPLE_FTRACE_DIRECT=m"
> > -  exit_unresolved;
> > +  exit_unsupported;
> >  fi
> >
> >  if [ ! -f kprobe_events ]; then
> > diff --git a/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc 
> > b/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
> > index b02550b..dd8b10d 100644
> > --- a/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
> > @@ -5,7 +5,7 @@
> >  rmmod trace-printk ||:
> >  if ! modprobe trace-printk ; then
> >echo "No trace-printk sample module - please make 
> > CONFIG_SAMPLE_TRACE_PRINTK=m"
> > -  exit_unresolved;
> > +  exit_unsupported;
> >  fi
> >
> >  echo "Waiting for irq work"
> > diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc 
> > b/tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc
> > index 1a4b4a4..26dc06a 100644
> > --- a/tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc
> > @@ -13,7 +13,7 @@ echo '*:mod:trace_printk' > set_ftrace_filter
> >  if ! modprobe trace-printk ; then
> >echo "No trace-printk sample module - please make 
> > CONFIG_SAMPLE_TRACE_PRINTK=
> >  m"
> > -  exit_unresolved;
> > +  exit_unsupported;
> >  fi
> >
> >  : "Wildcard should be resolved after loading module"
> > diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc 
> > b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
> > index d861bd7..4e07c69 100644
> > --- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
> > @@ -8,7 +8,7 @@ rmmod trace-printk ||:
> >  if ! modprobe trace-printk ; then
> >echo "No trace-printk sample module - please make 
> > CONFIG_SAMPLE_TRACE_PRINTK=
> >  m"
> > -  exit_unresolved;
> > +  exit_unsupported;
> >  fi
> >
> >  MOD=trace_printk
>


[PATCH] selftests/ftrace: treat module requirement unmet situation as unsupported

2020-04-29 Thread Po-Hsu Lin
When the required module for the test does not exist, use
exit_unsupported instead of exit_unresolved to indicate this test is
not supported.

By doing this we can make test behaviour in sync with the
irqsoff_tracer.tc test in preemptirq, which is also treating module
existence in this way. Moreover, the test won't exit with a non-zero
return value if the module does not exist.

Fixes: 646f01ccdd59 ("ftrace/selftest: Add tests to test 
register_ftrace_direct()")
Fixes: 4d23e9b4fd2e ("selftests/ftrace: Add trace_printk sample module test")
Fixes: 7bc026d6c032 ("selftests/ftrace: Add function filter on module testcase")
Fixes: af2a0750f374 ("selftests/ftrace: Improve kprobe on module testcase to 
load/unload module")
Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc  | 2 +-
 tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc  | 2 +-
 tools/testing/selftests/ftrace/test.d/event/trace_printk.tc| 2 +-
 tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc | 2 +-
 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc  | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc 
b/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc
index d75a869..3d6189e 100644
--- a/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc
+++ b/tools/testing/selftests/ftrace/test.d/direct/ftrace-direct.tc
@@ -5,7 +5,7 @@
 rmmod ftrace-direct ||:
 if ! modprobe ftrace-direct ; then
   echo "No ftrace-direct sample module - please make 
CONFIG_SAMPLE_FTRACE_DIRECT=m"
-  exit_unresolved;
+  exit_unsupported;
 fi
 
 echo "Let the module run a little"
diff --git a/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc 
b/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
index 801ecb6..3d0e3ca 100644
--- a/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
+++ b/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
@@ -5,7 +5,7 @@
 rmmod ftrace-direct ||:
 if ! modprobe ftrace-direct ; then
   echo "No ftrace-direct sample module - please build with 
CONFIG_SAMPLE_FTRACE_DIRECT=m"
-  exit_unresolved;
+  exit_unsupported;
 fi
 
 if [ ! -f kprobe_events ]; then
diff --git a/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc 
b/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
index b02550b..dd8b10d 100644
--- a/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
+++ b/tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
@@ -5,7 +5,7 @@
 rmmod trace-printk ||:
 if ! modprobe trace-printk ; then
   echo "No trace-printk sample module - please make 
CONFIG_SAMPLE_TRACE_PRINTK=m"
-  exit_unresolved;
+  exit_unsupported;
 fi
 
 echo "Waiting for irq work"
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc 
b/tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc
index 1a4b4a4..26dc06a 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/func_mod_trace.tc
@@ -13,7 +13,7 @@ echo '*:mod:trace_printk' > set_ftrace_filter
 if ! modprobe trace-printk ; then
   echo "No trace-printk sample module - please make CONFIG_SAMPLE_TRACE_PRINTK=
 m"
-  exit_unresolved;
+  exit_unsupported;
 fi
 
 : "Wildcard should be resolved after loading module"
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc 
b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
index d861bd7..4e07c69 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
@@ -8,7 +8,7 @@ rmmod trace-printk ||:
 if ! modprobe trace-printk ; then
   echo "No trace-printk sample module - please make CONFIG_SAMPLE_TRACE_PRINTK=
 m"
-  exit_unresolved;
+  exit_unsupported;
 fi
 
 MOD=trace_printk
-- 
2.7.4



Re: [PATCH] selftests/ftrace: skip ftrace test if FTRACE was not enabled

2019-07-04 Thread Po-Hsu Lin
Hello,
Thanks all for your feedback!

On Wed, Jul 3, 2019 at 8:11 AM Masami Hiramatsu  wrote:
>
> Hi Po-Hsu Lin,
>
> On Tue, 2 Jul 2019 13:22:26 -0600
> shuah  wrote:
>
> > Hi Po-Hsu Lin,
> >
> > On 7/2/19 12:23 AM, Po-Hsu Lin wrote:
> > > The ftrace test will need to have CONFIG_FTRACE enabled to make the
> > > ftrace directory available.
> > >
> > > Add an additional check to skip this test if the CONFIG_FTRACE was not
> > > enabled.
>
> Sorry, NAK for config check.
>
> > >
> > > This will be helpful to avoid a false-positive test result when testing
> > > it directly with the following commad against a kernel that does not
> > > have CONFIG_FTRACE enabled:
>
> Would you know tools/testing/selftests/ftrace/config (and other config files
> in each tests) ?
>
> Since each selftest depends specific configurations, those configs are
> written in config file, and tester must enable it using
> "scripts/kconfig/merge_config.sh".
>
> We can not check the kernel config in some cases, e.g. distro kernel,
> cross-build kernel, remote build kernel etc. Also, the .config file
> can be a config file for another kernel build.
>
> So please take care of your kernel configuration. If you find any test
> failed even if you enable configs in config file under that test, please
> report it, since that is a bug.
>
Yes I'm aware the config file.

People can still run a test directly without enabling corresponding
configs, so I think it's better to skip it if possible, directory
checking proposed by Steven looks better for this.

And thank you the explanation about the possible issue for a config check.

>
> Thank you,
>
> > >  make -C tools/testing/selftests TARGETS=ftrace run_tests
> > >
> > > The test result on an Ubuntu KVM kernel will be changed from:
> > >  selftests: ftrace: ftracetest
> > >  
> > >  Error: No ftrace directory found
> > >  not ok 1..1 selftests: ftrace: ftracetest [FAIL]
> > > To:
> >
> > Thanks for the patch.
> >
> > Check patch fails with the above To:
> >
> > WARNING: Use a single space after To:
> > #107:
> > To:
> >
> > ERROR: Unrecognized email address: ''
> > #107:
> > To:
> >
> > total: 1 errors, 1 warnings, 23 lines checked
> >

This is an interesting error here,
it looks like this checkpatch.pl script cannot identify the "To:" is
actually located inside the commit message.
I have to change this into something else to avoid this error.


> >
> > Please fix and send v2.
> >
> > >  selftests: ftrace: ftracetest
> > >  
> > >  CONFIG_FTRACE was not enabled, test skipped.
> > >  not ok 1..1 selftests: ftrace: ftracetest [SKIP]
> > >
> > > Signed-off-by: Po-Hsu Lin 
> > > ---
> > >   tools/testing/selftests/ftrace/ftracetest | 11 ++-
> > >   1 file changed, 10 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/testing/selftests/ftrace/ftracetest 
> > > b/tools/testing/selftests/ftrace/ftracetest
> > > index 6d5e9e8..6c8322e 100755
> > > --- a/tools/testing/selftests/ftrace/ftracetest
> > > +++ b/tools/testing/selftests/ftrace/ftracetest
> > > @@ -7,6 +7,9 @@
> > >   #  Written by Masami Hiramatsu 
> > >   #
> >
> > Hmm. You havem't cc'ed Masami on this. Adding Masami.
> >
> > I would think Masami should be on the Signed-off-by as well,
> > since he is the author.
> >
> > >
> > > +# Kselftest framework requirement - SKIP code is 4.
> > > +ksft_skip=4
> > > +
> > >   usage() { # errno [message]
> > >   [ ! -z "$2" ] && echo $2
> > >   echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]"
> > > @@ -139,7 +142,13 @@ parse_opts $*
> > >
> > >   # Verify parameters
> > >   if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then
> > > -  errexit "No ftrace directory found"
> > > +  ftrace_enabled=`grep "^CONFIG_FTRACE=y" /lib/modules/$(uname 
> > > -r)/build/.config`
> > > +  if [ -z "$ftrace_enabled" ]; then
> > > +echo "CONFIG_FTRACE was not enabled, test skipped."
> > > +exit $ksft_skip
> > > +  else
> > > +errexit "No ftrace directory found"
> > > +  fi
> > >   fi
> > >
> > >   # Preparing logs
> > >
> >
> > thanks,
> > -- Shuah
>
>
> --
> Masami Hiramatsu 


[PATCH] selftests/ftrace: skip ftrace test if FTRACE was not enabled

2019-07-02 Thread Po-Hsu Lin
The ftrace test will need to have CONFIG_FTRACE enabled to make the
ftrace directory available.

Add an additional check to skip this test if the CONFIG_FTRACE was not
enabled.

This will be helpful to avoid a false-positive test result when testing
it directly with the following commad against a kernel that does not
have CONFIG_FTRACE enabled:
make -C tools/testing/selftests TARGETS=ftrace run_tests

The test result on an Ubuntu KVM kernel will be changed from:
selftests: ftrace: ftracetest

Error: No ftrace directory found
not ok 1..1 selftests: ftrace: ftracetest [FAIL]
To:
selftests: ftrace: ftracetest

CONFIG_FTRACE was not enabled, test skipped.
not ok 1..1 selftests: ftrace: ftracetest [SKIP]

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/ftrace/ftracetest | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/ftrace/ftracetest 
b/tools/testing/selftests/ftrace/ftracetest
index 6d5e9e8..6c8322e 100755
--- a/tools/testing/selftests/ftrace/ftracetest
+++ b/tools/testing/selftests/ftrace/ftracetest
@@ -7,6 +7,9 @@
 #  Written by Masami Hiramatsu 
 #
 
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+
 usage() { # errno [message]
 [ ! -z "$2" ] && echo $2
 echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]"
@@ -139,7 +142,13 @@ parse_opts $*
 
 # Verify parameters
 if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then
-  errexit "No ftrace directory found"
+  ftrace_enabled=`grep "^CONFIG_FTRACE=y" /lib/modules/$(uname 
-r)/build/.config`
+  if [ -z "$ftrace_enabled" ]; then
+echo "CONFIG_FTRACE was not enabled, test skipped."
+exit $ksft_skip
+  else
+errexit "No ftrace directory found"
+  fi
 fi
 
 # Preparing logs
-- 
2.7.4



[PATCHv2] selftests/net: skip psock_tpacket test if KALLSYMS was not enabled

2019-06-30 Thread Po-Hsu Lin
The psock_tpacket test will need to access /proc/kallsyms, this would
require the kernel config CONFIG_KALLSYMS to be enabled first.

Apart from adding CONFIG_KALLSYMS to the net/config file here, check the
file existence to determine if we can run this test will be helpful to
avoid a false-positive test result when testing it directly with the
following commad against a kernel that have CONFIG_KALLSYMS disabled:
make -C tools/testing/selftests TARGETS=net run_tests

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/config|  1 +
 tools/testing/selftests/net/run_afpackettests | 14 +-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/net/config 
b/tools/testing/selftests/net/config
index 4740404..3dea2cb 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -25,3 +25,4 @@ CONFIG_NF_TABLES_IPV6=y
 CONFIG_NF_TABLES_IPV4=y
 CONFIG_NFT_CHAIN_NAT_IPV6=m
 CONFIG_NFT_CHAIN_NAT_IPV4=m
+CONFIG_KALLSYMS=y
diff --git a/tools/testing/selftests/net/run_afpackettests 
b/tools/testing/selftests/net/run_afpackettests
index ea5938e..8b42e8b 100755
--- a/tools/testing/selftests/net/run_afpackettests
+++ b/tools/testing/selftests/net/run_afpackettests
@@ -21,12 +21,16 @@ fi
 echo ""
 echo "running psock_tpacket test"
 echo ""
-./in_netns.sh ./psock_tpacket
-if [ $? -ne 0 ]; then
-   echo "[FAIL]"
-   ret=1
+if [ -f /proc/kallsyms ]; then
+   ./in_netns.sh ./psock_tpacket
+   if [ $? -ne 0 ]; then
+   echo "[FAIL]"
+   ret=1
+   else
+   echo "[PASS]"
+   fi
 else
-   echo "[PASS]"
+   echo "[SKIP] CONFIG_KALLSYMS not enabled"
 fi
 
 echo ""
-- 
2.7.4



Re: [PATCH] selftests/net: skip psock_tpacket test if KALLSYMS was not enabled

2019-06-13 Thread Po-Hsu Lin
Hello,

This issue was spotted on Ubuntu linux-kvm kernel, on which the
CONFIG_KALLSYMS was disabled intentionally.
I think this extra check could be helpful when running the net test directly.
$ make -C tools/testing/selftests TARGETS=net run_tests

Also, there is an identical check implemented in the ftrace
kprobe_args_symbol test.

I can send V2 along with CONFIG_KALLSYMS appended to the "config" file
if you agree with this.

Thanks

On Thu, Jun 13, 2019 at 12:27 AM David Miller  wrote:
>
> From: Po-Hsu Lin 
> Date: Wed, 12 Jun 2019 14:47:52 +0800
>
> > The psock_tpacket test will need to access /proc/kallsyms, this would
> > require the kernel config CONFIG_KALLSYMS to be enabled first.
> >
> > Check the file existence to determine if we can run this test.
> >
> > Signed-off-by: Po-Hsu Lin 
>
> Please just add CONFIG_KALLSYMS to "config".


[PATCH] selftests/net: skip psock_tpacket test if KALLSYMS was not enabled

2019-06-12 Thread Po-Hsu Lin
The psock_tpacket test will need to access /proc/kallsyms, this would
require the kernel config CONFIG_KALLSYMS to be enabled first.

Check the file existence to determine if we can run this test.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/net/run_afpackettests | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/net/run_afpackettests 
b/tools/testing/selftests/net/run_afpackettests
index ea5938e..8b42e8b 100755
--- a/tools/testing/selftests/net/run_afpackettests
+++ b/tools/testing/selftests/net/run_afpackettests
@@ -21,12 +21,16 @@ fi
 echo ""
 echo "running psock_tpacket test"
 echo ""
-./in_netns.sh ./psock_tpacket
-if [ $? -ne 0 ]; then
-   echo "[FAIL]"
-   ret=1
+if [ -f /proc/kallsyms ]; then
+   ./in_netns.sh ./psock_tpacket
+   if [ $? -ne 0 ]; then
+   echo "[FAIL]"
+   ret=1
+   else
+   echo "[PASS]"
+   fi
 else
-   echo "[PASS]"
+   echo "[SKIP] CONFIG_KALLSYMS not enabled"
 fi
 
 echo ""
-- 
2.7.4



Re: [PATCHv2] selftests/efivarfs: clean up test files from test_create*()

2019-04-19 Thread Po-Hsu Lin
Hello,

Commit f8a0590f fix some part of this issue.
I will send out V3 base on this commit in linux-kselftest next branch.

Thank you.


On Fri, Apr 19, 2019 at 9:20 PM shuah  wrote:
>
> On 4/19/19 7:12 AM, Po-Hsu Lin wrote:
> > Test files created by test_create*() tests will stay in the
> > $efivarfs_mount directory unless the system was rebooted.
> >
> > When the tester tries to run this efivarfs test again on the same
> > system, the immutable characteristics in that directory will cause some
> > "Operation not permitted" noises and a false-positve test result to the
> > test_create_read() test.
> >
> >  
> >  running test_create
> >  
> >  ./efivarfs.sh: line 59: 
> > /sys/firmware/efi/efivars/test_create-210be57c-9849-4fc7-a635-e6382d1aec27: 
> > Operation not permitted
> >[PASS]
> >  
> >  running test_create_empty
> >  
> >  ./efivarfs.sh: line 78: 
> > /sys/firmware/efi/efivars/test_create_empty-210be57c-9849-4fc7-a635-e6382d1aec27:
> >  Operation not permitted
> >   [PASS]
> >  
> >  running test_create_read
> >  
> >  open(O_WRONLY): Operation not permitted
> >   [FAIL]
> >  
> >
> > Create a file_cleanup() to remove those test files in the end of each
> > test to solve this issue.
> >
> > Also, use this function to replace the existing file removal code.
> >
> > Link: https://bugs.launchpad.net/bugs/1809704
> >
> > Signed-off-by: Po-Hsu Lin 
> > ---
>
> Thanks for the patch. There is another patch that does the same in
> linux-kselftest next branch.
>
> Please check to see if that fixes the problem you are seeing.
>
> thanks,
> -- Shuah
>


[PATCHv2] selftests/efivarfs: clean up test files from test_create*()

2019-04-19 Thread Po-Hsu Lin
Test files created by test_create*() tests will stay in the
$efivarfs_mount directory unless the system was rebooted.

When the tester tries to run this efivarfs test again on the same
system, the immutable characteristics in that directory will cause some
"Operation not permitted" noises and a false-positve test result to the
test_create_read() test.


running test_create

./efivarfs.sh: line 59: 
/sys/firmware/efi/efivars/test_create-210be57c-9849-4fc7-a635-e6382d1aec27: 
Operation not permitted
  [PASS]

running test_create_empty

./efivarfs.sh: line 78: 
/sys/firmware/efi/efivars/test_create_empty-210be57c-9849-4fc7-a635-e6382d1aec27:
 Operation not permitted
 [PASS]

running test_create_read

open(O_WRONLY): Operation not permitted
 [FAIL]


Create a file_cleanup() to remove those test files in the end of each
test to solve this issue.

Also, use this function to replace the existing file removal code.

Link: https://bugs.launchpad.net/bugs/1809704

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/efivarfs/efivarfs.sh | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)
 mode change 100755 => 100644 tools/testing/selftests/efivarfs/efivarfs.sh

diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh 
b/tools/testing/selftests/efivarfs/efivarfs.sh
old mode 100755
new mode 100644
index a47029a..14fa6fe
--- a/tools/testing/selftests/efivarfs/efivarfs.sh
+++ b/tools/testing/selftests/efivarfs/efivarfs.sh
@@ -7,6 +7,12 @@ test_guid=210be57c-9849-4fc7-a635-e6382d1aec27
 # Kselftest framework requirement - SKIP code is 4.
 ksft_skip=4
 
+file_cleanup()
+{
+   chattr -i $1
+   rm $1
+}
+
 check_prereqs()
 {
local msg="skip all tests:"
@@ -58,8 +64,10 @@ test_create()
 
if [ $(stat -c %s $file) -ne 5 ]; then
echo "$file has invalid size" >&2
+   file_cleanup $file
exit 1
fi
+   file_cleanup $file
 }
 
 test_create_empty()
@@ -72,12 +80,14 @@ test_create_empty()
echo "$file can not be created without writing" >&2
exit 1
fi
+   file_cleanup $file
 }
 
 test_create_read()
 {
local file=$efivarfs_mount/$FUNCNAME-$test_guid
./create-read $file
+   file_cleanup $file
 }
 
 test_delete()
@@ -94,8 +104,7 @@ test_delete()
 
rm $file 2>/dev/null
if [ $? -ne 0 ]; then
-   chattr -i $file
-   rm $file
+   file_cleanup $file
fi
 
if [ -e $file ]; then
@@ -152,8 +161,7 @@ test_valid_filenames()
else
rm $file 2>/dev/null
if [ $? -ne 0 ]; then
-   chattr -i $file
-   rm $file
+   file_cleanup $file
fi
fi
done
@@ -189,8 +197,7 @@ test_invalid_filenames()
echo "Creating $file should have failed" >&2
rm $file 2>/dev/null
if [ $? -ne 0 ]; then
-   chattr -i $file
-   rm $file
+   file_cleanup $file
fi
ret=1
fi
-- 
2.7.4



[PATCHv3] selftests/efivarfs: clean up test files from test_create*()

2019-04-19 Thread Po-Hsu Lin
Test files created by test_create() and test_create_empty() tests will
stay in the $efivarfs_mount directory until the system was rebooted.

When the tester tries to run this efivarfs test again on the same
system, the immutable characteristics in that directory will cause some
"Operation not permitted" noises, and a false-positve test result as the
file was created in previous run.

running test_create

./efivarfs.sh: line 59: 
/sys/firmware/efi/efivars/test_create-210be57c-9849-4fc7-a635-e6382d1aec27: 
Operation not permitted
  [PASS]

running test_create_empty

./efivarfs.sh: line 78: 
/sys/firmware/efi/efivars/test_create_empty-210be57c-9849-4fc7-a635-e6382d1aec27:
 Operation not permitted
 [PASS]


Create a file_cleanup() to remove those test files in the end of each
test to solve this issue.

For the test_create_read, we can move the clean up task to the end of
the test to ensure the system is clean.

Also, use this function to replace the existing file removal code.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/efivarfs/efivarfs.sh | 32 +++-
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh 
b/tools/testing/selftests/efivarfs/efivarfs.sh
index d386610..a90f394 100755
--- a/tools/testing/selftests/efivarfs/efivarfs.sh
+++ b/tools/testing/selftests/efivarfs/efivarfs.sh
@@ -7,6 +7,12 @@ test_guid=210be57c-9849-4fc7-a635-e6382d1aec27
 # Kselftest framework requirement - SKIP code is 4.
 ksft_skip=4
 
+file_cleanup()
+{
+   chattr -i $1
+   rm -f $1
+}
+
 check_prereqs()
 {
local msg="skip all tests:"
@@ -58,8 +64,10 @@ test_create()
 
if [ $(stat -c %s $file) -ne 5 ]; then
echo "$file has invalid size" >&2
+   file_cleanup $file
exit 1
fi
+   file_cleanup $file
 }
 
 test_create_empty()
@@ -72,16 +80,14 @@ test_create_empty()
echo "$file can not be created without writing" >&2
exit 1
fi
+   file_cleanup $file
 }
 
 test_create_read()
 {
local file=$efivarfs_mount/$FUNCNAME-$test_guid
-   if [ -f $file]; then
-   chattr -i $file
-   rm -rf $file
-   fi
./create-read $file
+   file_cleanup $file
 }
 
 test_delete()
@@ -96,11 +102,7 @@ test_delete()
exit 1
fi
 
-   rm $file 2>/dev/null
-   if [ $? -ne 0 ]; then
-   chattr -i $file
-   rm $file
-   fi
+   file_cleanup $file
 
if [ -e $file ]; then
echo "$file couldn't be deleted" >&2
@@ -154,11 +156,7 @@ test_valid_filenames()
echo "$file could not be created" >&2
ret=1
else
-   rm $file 2>/dev/null
-   if [ $? -ne 0 ]; then
-   chattr -i $file
-   rm $file
-   fi
+   file_cleanup $file
fi
done
 
@@ -191,11 +189,7 @@ test_invalid_filenames()
 
if [ -e $file ]; then
echo "Creating $file should have failed" >&2
-   rm $file 2>/dev/null
-   if [ $? -ne 0 ]; then
-   chattr -i $file
-   rm $file
-   fi
+   file_cleanup $file
ret=1
fi
done
-- 
2.7.4



[PATCH] selftests: cpu-hotplug: check hotplug dir for the CONFIG_HOTPLUG_CPU

2019-03-12 Thread Po-Hsu Lin
When the CONFIG_HOTPLUG_CPU is not set, there won't be a "hotplug"
directory in /sys/devices/system/cpu/. Make use of this fact to check
if we need to skip this test.

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh 
b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
index 0d26b5e..27275a1 100755
--- a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
+++ b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
@@ -23,6 +23,11 @@ prerequisite()
exit $ksft_skip
fi
 
+   if [ ! -d $SYSFS/devices/system/cpu/hotplug/ ]; then
+   echo $msg CONFIG_HOTPLUG_CPU needs to be enabled >&2
+   exit $ksft_skip
+   fi
+
if ! ls $SYSFS/devices/system/cpu/cpu* > /dev/null 2>&1; then
echo $msg cpu hotplug is not supported >&2
exit $ksft_skip
-- 
2.7.4



[PATCH] selftests/efivarfs: clean up test files from test_create*()

2018-12-25 Thread Po-Hsu Lin
Test files created by test_create*() tests will stay in the $efivarfs_mount
directory until next reboot.

When the tester tries to run this efivarfs test again on the same system, the
immutable characteristics in that directory with those previously generated
files will cause some "Permission denied" noises and a false-positive test
result to the test_create_read() test.

Remove those test files in the end of each test to solve this issue.

Link: https://bugs.launchpad.net/bugs/1809704

Signed-off-by: Po-Hsu Lin 
---
 tools/testing/selftests/efivarfs/efivarfs.sh | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh 
b/tools/testing/selftests/efivarfs/efivarfs.sh
index a47029a..ea2e2a0 100755
--- a/tools/testing/selftests/efivarfs/efivarfs.sh
+++ b/tools/testing/selftests/efivarfs/efivarfs.sh
@@ -60,6 +60,12 @@ test_create()
echo "$file has invalid size" >&2
exit 1
fi
+
+rm $file 2>/dev/null
+if [ $? -ne 0 ]; then
+chattr -i $file
+rm $file
+fi
 }
 
 test_create_empty()
@@ -72,12 +78,24 @@ test_create_empty()
echo "$file can not be created without writing" >&2
exit 1
fi
+
+rm $file 2>/dev/null
+if [ $? -ne 0 ]; then
+chattr -i $file
+rm $file
+fi
 }
 
 test_create_read()
 {
local file=$efivarfs_mount/$FUNCNAME-$test_guid
./create-read $file
+
+rm $file 2>/dev/null
+if [ $? -ne 0 ]; then
+chattr -i $file
+rm $file
+fi
 }
 
 test_delete()
-- 
2.7.4



[PATCHv2 5/5] selftests: fix memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
In the memory offline test, the $ration was used with RANDOM as the
possibility to get it offlined, correct it to become the portion of
available removable memory blocks.

Also ask the tool to try to offline the next available memory block
if the attempt is unsuccessful. It will only fail if all removable
memory blocks are busy.

A nice example:
$ sudo ./test.sh
Test scope: 10% hotplug memory
online all hot-pluggable memory in offline state:
SKIPPED - no hot-pluggable memory in offline state
offline 10% hot-pluggable memory in online state
trying to offline 3 out of 28 memory block(s):
online->offline memory1
online->offline memory10
./test.sh: line 74: echo: write error: Resource temporarily unavailable
offline_memory_expect_success 10: unexpected fail
online->offline memory100
online->offline memory101
online all hot-pluggable memory in offline state:
offline->online memory1
offline->online memory100
offline->online memory101
skip extra tests: debugfs is not mounted
$ echo $?
0

Signed-off-by: Po-Hsu Lin <po-hsu@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|   70 +++-
 1 file changed, 54 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 0f62c16..35025ce 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -80,9 +80,12 @@ online_memory_expect_success()
 
if ! online_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2
+   return 1
elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 online_memory_expect_fail()
@@ -91,9 +94,12 @@ online_memory_expect_fail()
 
if online_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2
+   return 1
elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected online >&2
+   return 1
fi
+   return 0
 }
 
 offline_memory_expect_success()
@@ -102,9 +108,12 @@ offline_memory_expect_success()
 
if ! offline_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2
+   return 1
elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 offline_memory_expect_fail()
@@ -113,14 +122,18 @@ offline_memory_expect_fail()
 
if offline_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2
+   return 1
elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 error=-12
 priority=0
 ratio=10
+retval=0
 
 while getopts e:hp:r: opt; do
case $opt in
@@ -152,35 +165,58 @@ fi
 prerequisite
 
 echo "Test scope: $ratio% hotplug memory"
-echo -e "\t online all hotplug memory in offline state"
-echo -e "\t offline $ratio% hotplug memory in online state"
-echo -e "\t online all hotplug memory in offline state"
 
 #
 # Online all hot-pluggable memory
 #
-for memory in `hotpluggable_offline_memory`; do
-   echo offline-online $memory
-   online_memory_expect_success $memory
-done
+hotpluggable_num=`hotpluggable_offline_memory | wc -l`
+echo -e "\t online all hot-pluggable memory in offline state:"
+if [ "$hotpluggable_num" -gt 0 ]; then
+   for memory in `hotpluggable_offline_memory`; do
+   echo "offline->online memory$memory"
+   if ! online_memory_expect_success $memory; then
+   retval=1
+   fi
+   done
+else
+   echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
+fi
 
 #
 # Offline $ratio percent of hot-pluggable memory
 #
+hotpluggable_num=`hotpluggable_online_memory | wc -l`
+target=`echo "a=$hotpluggable_num*$ratio; if ( a%100 ) a/100+1 else a/100" | 
bc`
+echo -e "\t offline $ratio% hot-pluggable memory in online state"
+echo -e "\t trying to offline $target out of $hotpluggable_num memory 
block(s):"
 for memory in `hotpluggable_online_memory`; do
-   if [ $((RANDOM % 100)) -lt $ratio ]; then
-   echo online-offline $memory
-   offline_memory_expect_success $memory
+   if [ "$target" -gt 0 ]; then
+   echo "online->offline memory$memory"
+   if offline_memory_expect_success $memory; then
+   target=$(

[PATCHv2 1/5] selftests: typo correction for memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
Typo fixed for hotpluggable_offline_memory() in memory-hotplug test.

Signed-off-by: Po-Hsu Lin <po-hsu@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|   10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 6cddde0..a8d8587 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -39,7 +39,7 @@ hotpluggable_memory()
done
 }
 
-hotplaggable_offline_memory()
+hotpluggable_offline_memory()
 {
hotpluggable_memory offline
 }
@@ -150,7 +150,7 @@ echo -e "\t online all hotplug memory in offline state"
 #
 # Online all hot-pluggable memory
 #
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
echo offline-online $memory
online_memory_expect_success $memory
 done
@@ -168,7 +168,7 @@ done
 #
 # Online all hot-pluggable memory again
 #
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
echo offline-online $memory
online_memory_expect_success $memory
 done
@@ -214,7 +214,7 @@ done
 # Test memory hot-add error handling (offline => online)
 #
 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
online_memory_expect_fail $memory
 done
 
@@ -222,7 +222,7 @@ done
 # Online all hot-pluggable memory
 #
 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
online_memory_expect_success $memory
 done
 
-- 
1.7.9.5



[PATCHv2 5/5] selftests: fix memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
In the memory offline test, the $ration was used with RANDOM as the
possibility to get it offlined, correct it to become the portion of
available removable memory blocks.

Also ask the tool to try to offline the next available memory block
if the attempt is unsuccessful. It will only fail if all removable
memory blocks are busy.

A nice example:
$ sudo ./test.sh
Test scope: 10% hotplug memory
online all hot-pluggable memory in offline state:
SKIPPED - no hot-pluggable memory in offline state
offline 10% hot-pluggable memory in online state
trying to offline 3 out of 28 memory block(s):
online->offline memory1
online->offline memory10
./test.sh: line 74: echo: write error: Resource temporarily unavailable
offline_memory_expect_success 10: unexpected fail
online->offline memory100
online->offline memory101
online all hot-pluggable memory in offline state:
offline->online memory1
offline->online memory100
offline->online memory101
skip extra tests: debugfs is not mounted
$ echo $?
0

Signed-off-by: Po-Hsu Lin 
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|   70 +++-
 1 file changed, 54 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 0f62c16..35025ce 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -80,9 +80,12 @@ online_memory_expect_success()
 
if ! online_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2
+   return 1
elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 online_memory_expect_fail()
@@ -91,9 +94,12 @@ online_memory_expect_fail()
 
if online_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2
+   return 1
elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected online >&2
+   return 1
fi
+   return 0
 }
 
 offline_memory_expect_success()
@@ -102,9 +108,12 @@ offline_memory_expect_success()
 
if ! offline_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2
+   return 1
elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 offline_memory_expect_fail()
@@ -113,14 +122,18 @@ offline_memory_expect_fail()
 
if offline_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2
+   return 1
elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 error=-12
 priority=0
 ratio=10
+retval=0
 
 while getopts e:hp:r: opt; do
case $opt in
@@ -152,35 +165,58 @@ fi
 prerequisite
 
 echo "Test scope: $ratio% hotplug memory"
-echo -e "\t online all hotplug memory in offline state"
-echo -e "\t offline $ratio% hotplug memory in online state"
-echo -e "\t online all hotplug memory in offline state"
 
 #
 # Online all hot-pluggable memory
 #
-for memory in `hotpluggable_offline_memory`; do
-   echo offline-online $memory
-   online_memory_expect_success $memory
-done
+hotpluggable_num=`hotpluggable_offline_memory | wc -l`
+echo -e "\t online all hot-pluggable memory in offline state:"
+if [ "$hotpluggable_num" -gt 0 ]; then
+   for memory in `hotpluggable_offline_memory`; do
+   echo "offline->online memory$memory"
+   if ! online_memory_expect_success $memory; then
+   retval=1
+   fi
+   done
+else
+   echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
+fi
 
 #
 # Offline $ratio percent of hot-pluggable memory
 #
+hotpluggable_num=`hotpluggable_online_memory | wc -l`
+target=`echo "a=$hotpluggable_num*$ratio; if ( a%100 ) a/100+1 else a/100" | 
bc`
+echo -e "\t offline $ratio% hot-pluggable memory in online state"
+echo -e "\t trying to offline $target out of $hotpluggable_num memory 
block(s):"
 for memory in `hotpluggable_online_memory`; do
-   if [ $((RANDOM % 100)) -lt $ratio ]; then
-   echo online-offline $memory
-   offline_memory_expect_success $memory
+   if [ "$target" -gt 0 ]; then
+   echo "online->offline memory$memory"
+   if offline_memory_expect_success $memory; then
+   target=$(($target - 1))
+   

[PATCHv2 1/5] selftests: typo correction for memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
Typo fixed for hotpluggable_offline_memory() in memory-hotplug test.

Signed-off-by: Po-Hsu Lin 
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|   10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 6cddde0..a8d8587 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -39,7 +39,7 @@ hotpluggable_memory()
done
 }
 
-hotplaggable_offline_memory()
+hotpluggable_offline_memory()
 {
hotpluggable_memory offline
 }
@@ -150,7 +150,7 @@ echo -e "\t online all hotplug memory in offline state"
 #
 # Online all hot-pluggable memory
 #
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
echo offline-online $memory
online_memory_expect_success $memory
 done
@@ -168,7 +168,7 @@ done
 #
 # Online all hot-pluggable memory again
 #
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
echo offline-online $memory
online_memory_expect_success $memory
 done
@@ -214,7 +214,7 @@ done
 # Test memory hot-add error handling (offline => online)
 #
 echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
online_memory_expect_fail $memory
 done
 
@@ -222,7 +222,7 @@ done
 # Online all hot-pluggable memory
 #
 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
-for memory in `hotplaggable_offline_memory`; do
+for memory in `hotpluggable_offline_memory`; do
online_memory_expect_success $memory
 done
 
-- 
1.7.9.5



[PATCHv2 3/5] selftests: check percentage range for memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
Check the precentage range for -r flag in memory-hotplug test.

Signed-off-by: Po-Hsu Lin <po-hsu@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|4 
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 993ff2b..c735ece 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -136,6 +136,10 @@ while getopts e:hp:r: opt; do
;;
r)
ratio=$OPTARG
+   if [ "$ratio" -gt 100 ] || [ "$ratio" -lt 0 ]; then
+   echo "The percentage should be an integer within 0~100 
range"
+   exit 1
+   fi
;;
esac
 done
-- 
1.7.9.5



[PATCHv2 2/5] selftests: check hot-pluggagble memory for memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
Check for hot-pluggable memory availability in prerequisite() of the
memory-hotplug test.

Signed-off-by: Po-Hsu Lin <po-hsu@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index a8d8587..993ff2b 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -22,6 +22,11 @@ prerequisite()
echo $msg memory hotplug is not supported >&2
exit 0
fi
+
+   if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
+   echo $msg no hot-pluggable memory >&2
+   exit 0
+   fi
 }
 
 #
-- 
1.7.9.5



[PATCHv2 3/5] selftests: check percentage range for memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
Check the precentage range for -r flag in memory-hotplug test.

Signed-off-by: Po-Hsu Lin 
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|4 
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 993ff2b..c735ece 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -136,6 +136,10 @@ while getopts e:hp:r: opt; do
;;
r)
ratio=$OPTARG
+   if [ "$ratio" -gt 100 ] || [ "$ratio" -lt 0 ]; then
+   echo "The percentage should be an integer within 0~100 
range"
+   exit 1
+   fi
;;
esac
 done
-- 
1.7.9.5



[PATCHv2 2/5] selftests: check hot-pluggagble memory for memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
Check for hot-pluggable memory availability in prerequisite() of the
memory-hotplug test.

Signed-off-by: Po-Hsu Lin 
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index a8d8587..993ff2b 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -22,6 +22,11 @@ prerequisite()
echo $msg memory hotplug is not supported >&2
exit 0
fi
+
+   if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
+   echo $msg no hot-pluggable memory >&2
+   exit 0
+   fi
 }
 
 #
-- 
1.7.9.5



[PATCHv2 0/5] selftests: fix memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
This patchset will fix a typo, print the name of the memory notifier
error injection test, add two extra checks and fixes the online /
offline memory test in the memory-hotplug test.

Po-Hsu Lin (5):
  selftests: typo correction for memory-hotplug test
  selftests: check hot-pluggagble memory for memory-hotplug test
  selftests: check percentage range for memory-hotplug test
  selftests: add missing test name in memory-hotplug test
  selftests: fix memory-hotplug test

 .../selftests/memory-hotplug/mem-on-off-test.sh|   86 +++-
 1 file changed, 67 insertions(+), 19 deletions(-)

-- 
1.7.9.5



[PATCHv2 0/5] selftests: fix memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
This patchset will fix a typo, print the name of the memory notifier
error injection test, add two extra checks and fixes the online /
offline memory test in the memory-hotplug test.

Po-Hsu Lin (5):
  selftests: typo correction for memory-hotplug test
  selftests: check hot-pluggagble memory for memory-hotplug test
  selftests: check percentage range for memory-hotplug test
  selftests: add missing test name in memory-hotplug test
  selftests: fix memory-hotplug test

 .../selftests/memory-hotplug/mem-on-off-test.sh|   86 +++-
 1 file changed, 67 insertions(+), 19 deletions(-)

-- 
1.7.9.5



[PATCHv2 4/5] selftests: add missing test name in memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
There is no prompt for testing memory notifier error injection,
added with the same echo format of other tests above.

Signed-off-by: Po-Hsu Lin <po-hsu@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index c735ece..0f62c16 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -207,6 +207,7 @@ prerequisite_extra()
fi
 }
 
+echo -e "\t Test with memory notifier error injection"
 prerequisite_extra
 
 #
-- 
1.7.9.5



[PATCHv2 4/5] selftests: add missing test name in memory-hotplug test

2017-06-27 Thread Po-Hsu Lin
There is no prompt for testing memory notifier error injection,
added with the same echo format of other tests above.

Signed-off-by: Po-Hsu Lin 
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index c735ece..0f62c16 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -207,6 +207,7 @@ prerequisite_extra()
fi
 }
 
+echo -e "\t Test with memory notifier error injection"
 prerequisite_extra
 
 #
-- 
1.7.9.5



Re: [PATCH] selftests: fix memory-hotplug test

2017-06-26 Thread Po-Hsu Lin
Hello Shuah,

thanks for the feedback, I will send v2 for these.

Cheers

On Sat, Jun 24, 2017 at 12:03 AM, Shuah Khan <sh...@kernel.org> wrote:
> Hi Po-Hsu Lin,
>
> On 06/18/2017 09:04 PM, Po-Hsu Lin wrote:
>
> Please split the typo correction and fixes. Please send a patch
> for each individual fix. I am seeing several fixes bundled in this
> one single patch.
>
>> Typo correction for hotpluggable_offline_memory() function> Check for 
>> hot-pluggable memory availability in prerequisite().
>> Check for precentage range for -r flag>
>> Fix the memory offline test, the $ratio was used with RANDOM as the
>> possibility to get it offlined, correct it to become the portion of
>> available removable memory blocks.
>> Also ask the tool to try to offline the next available memory block
>> if the attempt is unsuccessful. It will only fail if all removable
>> memory blocks are busy.
>>
>> An nice example:
>> PHLin@Latitude:~$ sudo ./test.sh
>
> Remove the user info from this output. Same comment for the rest if
> this output.
>
>> Test scope: 10% hotplug memory
>>online all hot-pluggable memory in offline state:
>>   SKIPPED - no hot-pluggable memory in offline state
>>offline 10% hot-pluggable memory in online state
>>trying to offline 3 out of 28 memory block(s):
>> online->offline memory1
>> online->offline memory10
>> ./test.sh: line 74: echo: write error: Resource temporarily unavailable
>> offline_memory_expect_success 10: unexpected fail
>> online->offline memory100
>> online->offline memory101
>>online all hot-pluggable memory in offline state:
>> offline->online memory1
>> offline->online memory100
>> offline->online memory101
>> skip extra tests: debugfs is not mounted
>> PHLin@Latitude:~$ echo $?
>> 0
>>
>> Signed-off-by: Po-Hsu Lin <po-hsu@canonical.com>
>
> thanks,
> -- Shuah
>
>> ---
>>  .../selftests/memory-hotplug/mem-on-off-test.sh|   86 
>> +++-
>>  1 file changed, 67 insertions(+), 19 deletions(-)
>>
>> diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
>> b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
>> index 6cddde0..f1603e6 100755
>> --- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
>> +++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
>> @@ -22,6 +22,11 @@ prerequisite()
>>   echo $msg memory hotplug is not supported >&2
>>   exit 0
>>   fi
>> +
>> + if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
>> + echo $msg no hot-pluggable memory >&2
>> + exit 0
>> + fi
>>  }
>>
>>  #
>> @@ -39,7 +44,7 @@ hotpluggable_memory()
>>   done
>>  }
>>
>> -hotplaggable_offline_memory()
>> +hotpluggable_offline_memory()
>>  {
>>   hotpluggable_memory offline
>>  }
>> @@ -75,9 +80,12 @@ online_memory_expect_success()
>>
>>   if ! online_memory $memory; then
>>   echo $FUNCNAME $memory: unexpected fail >&2
>> + return 1
>>   elif ! memory_is_online $memory; then
>>   echo $FUNCNAME $memory: unexpected offline >&2
>> + return 1
>>   fi
>> + return 0
>>  }
>>
>>  online_memory_expect_fail()
>> @@ -86,9 +94,12 @@ online_memory_expect_fail()
>>
>>   if online_memory $memory 2> /dev/null; then
>>   echo $FUNCNAME $memory: unexpected success >&2
>> + return 1
>>   elif ! memory_is_offline $memory; then
>>   echo $FUNCNAME $memory: unexpected online >&2
>> + return 1
>>   fi
>> + return 0
>>  }
>>
>>  offline_memory_expect_success()
>> @@ -97,9 +108,12 @@ offline_memory_expect_success()
>>
>>   if ! offline_memory $memory; then
>>   echo $FUNCNAME $memory: unexpected fail >&2
>> + return 1
>>   elif ! memory_is_offline $memory; then
>>   echo $FUNCNAME $memory: unexpected offline >&2
>> + return 1
>>   fi
>> + return 0
>>  }
>>
>>  offline_memory_expect_fail()
>> @@ -108,14 +122,18 @@ offline_memory_expect_fail()
>>
>>   if offline_memory $memory 2> /dev/null; then
>>   echo $FUNCNAME $memory: unexpected success >&2
>

Re: [PATCH] selftests: fix memory-hotplug test

2017-06-26 Thread Po-Hsu Lin
Hello Shuah,

thanks for the feedback, I will send v2 for these.

Cheers

On Sat, Jun 24, 2017 at 12:03 AM, Shuah Khan  wrote:
> Hi Po-Hsu Lin,
>
> On 06/18/2017 09:04 PM, Po-Hsu Lin wrote:
>
> Please split the typo correction and fixes. Please send a patch
> for each individual fix. I am seeing several fixes bundled in this
> one single patch.
>
>> Typo correction for hotpluggable_offline_memory() function> Check for 
>> hot-pluggable memory availability in prerequisite().
>> Check for precentage range for -r flag>
>> Fix the memory offline test, the $ratio was used with RANDOM as the
>> possibility to get it offlined, correct it to become the portion of
>> available removable memory blocks.
>> Also ask the tool to try to offline the next available memory block
>> if the attempt is unsuccessful. It will only fail if all removable
>> memory blocks are busy.
>>
>> An nice example:
>> PHLin@Latitude:~$ sudo ./test.sh
>
> Remove the user info from this output. Same comment for the rest if
> this output.
>
>> Test scope: 10% hotplug memory
>>online all hot-pluggable memory in offline state:
>>   SKIPPED - no hot-pluggable memory in offline state
>>offline 10% hot-pluggable memory in online state
>>trying to offline 3 out of 28 memory block(s):
>> online->offline memory1
>> online->offline memory10
>> ./test.sh: line 74: echo: write error: Resource temporarily unavailable
>> offline_memory_expect_success 10: unexpected fail
>> online->offline memory100
>> online->offline memory101
>>online all hot-pluggable memory in offline state:
>> offline->online memory1
>> offline->online memory100
>> offline->online memory101
>> skip extra tests: debugfs is not mounted
>> PHLin@Latitude:~$ echo $?
>> 0
>>
>> Signed-off-by: Po-Hsu Lin 
>
> thanks,
> -- Shuah
>
>> ---
>>  .../selftests/memory-hotplug/mem-on-off-test.sh|   86 
>> +++-
>>  1 file changed, 67 insertions(+), 19 deletions(-)
>>
>> diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
>> b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
>> index 6cddde0..f1603e6 100755
>> --- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
>> +++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
>> @@ -22,6 +22,11 @@ prerequisite()
>>   echo $msg memory hotplug is not supported >&2
>>   exit 0
>>   fi
>> +
>> + if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
>> + echo $msg no hot-pluggable memory >&2
>> + exit 0
>> + fi
>>  }
>>
>>  #
>> @@ -39,7 +44,7 @@ hotpluggable_memory()
>>   done
>>  }
>>
>> -hotplaggable_offline_memory()
>> +hotpluggable_offline_memory()
>>  {
>>   hotpluggable_memory offline
>>  }
>> @@ -75,9 +80,12 @@ online_memory_expect_success()
>>
>>   if ! online_memory $memory; then
>>   echo $FUNCNAME $memory: unexpected fail >&2
>> + return 1
>>   elif ! memory_is_online $memory; then
>>   echo $FUNCNAME $memory: unexpected offline >&2
>> + return 1
>>   fi
>> + return 0
>>  }
>>
>>  online_memory_expect_fail()
>> @@ -86,9 +94,12 @@ online_memory_expect_fail()
>>
>>   if online_memory $memory 2> /dev/null; then
>>   echo $FUNCNAME $memory: unexpected success >&2
>> + return 1
>>   elif ! memory_is_offline $memory; then
>>   echo $FUNCNAME $memory: unexpected online >&2
>> + return 1
>>   fi
>> + return 0
>>  }
>>
>>  offline_memory_expect_success()
>> @@ -97,9 +108,12 @@ offline_memory_expect_success()
>>
>>   if ! offline_memory $memory; then
>>   echo $FUNCNAME $memory: unexpected fail >&2
>> + return 1
>>   elif ! memory_is_offline $memory; then
>>   echo $FUNCNAME $memory: unexpected offline >&2
>> + return 1
>>   fi
>> + return 0
>>  }
>>
>>  offline_memory_expect_fail()
>> @@ -108,14 +122,18 @@ offline_memory_expect_fail()
>>
>>   if offline_memory $memory 2> /dev/null; then
>>   echo $FUNCNAME $memory: unexpected success >&2
>> + return 1
>>   elif ! memo

[PATCH] selftests: fix memory-hotplug test

2017-06-18 Thread Po-Hsu Lin
Typo correction for hotpluggable_offline_memory() function.
Check for hot-pluggable memory availability in prerequisite().
Check for precentage range for -r flag.

Fix the memory offline test, the $ratio was used with RANDOM as the
possibility to get it offlined, correct it to become the portion of
available removable memory blocks.
Also ask the tool to try to offline the next available memory block
if the attempt is unsuccessful. It will only fail if all removable
memory blocks are busy.

An nice example:
PHLin@Latitude:~$ sudo ./test.sh
Test scope: 10% hotplug memory
 online all hot-pluggable memory in offline state:
SKIPPED - no hot-pluggable memory in offline state
 offline 10% hot-pluggable memory in online state
 trying to offline 3 out of 28 memory block(s):
online->offline memory1
online->offline memory10
./test.sh: line 74: echo: write error: Resource temporarily unavailable
offline_memory_expect_success 10: unexpected fail
online->offline memory100
online->offline memory101
 online all hot-pluggable memory in offline state:
offline->online memory1
offline->online memory100
offline->online memory101
skip extra tests: debugfs is not mounted
PHLin@Latitude:~$ echo $?
0

Signed-off-by: Po-Hsu Lin <po-hsu@canonical.com>
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|   86 +++-
 1 file changed, 67 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 6cddde0..f1603e6 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -22,6 +22,11 @@ prerequisite()
echo $msg memory hotplug is not supported >&2
exit 0
fi
+
+   if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
+   echo $msg no hot-pluggable memory >&2
+   exit 0
+   fi
 }
 
 #
@@ -39,7 +44,7 @@ hotpluggable_memory()
done
 }
 
-hotplaggable_offline_memory()
+hotpluggable_offline_memory()
 {
hotpluggable_memory offline
 }
@@ -75,9 +80,12 @@ online_memory_expect_success()
 
if ! online_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2
+   return 1
elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 online_memory_expect_fail()
@@ -86,9 +94,12 @@ online_memory_expect_fail()
 
if online_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2
+   return 1
elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected online >&2
+   return 1
fi
+   return 0
 }
 
 offline_memory_expect_success()
@@ -97,9 +108,12 @@ offline_memory_expect_success()
 
if ! offline_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2
+   return 1
elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 offline_memory_expect_fail()
@@ -108,14 +122,18 @@ offline_memory_expect_fail()
 
if offline_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2
+   return 1
elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 error=-12
 priority=0
 ratio=10
+retval=0
 
 while getopts e:hp:r: opt; do
case $opt in
@@ -131,6 +149,10 @@ while getopts e:hp:r: opt; do
;;
r)
ratio=$OPTARG
+   if [ "$ratio" -gt 100 ] || [ "$ratio" -lt 0 ]; then
+   echo "The percentage should be an integer within 0~100 
range"
+   exit
+   fi
;;
esac
 done
@@ -143,35 +165,58 @@ fi
 prerequisite
 
 echo "Test scope: $ratio% hotplug memory"
-echo -e "\t online all hotplug memory in offline state"
-echo -e "\t offline $ratio% hotplug memory in online state"
-echo -e "\t online all hotplug memory in offline state"
 
 #
 # Online all hot-pluggable memory
 #
-for memory in `hotplaggable_offline_memory`; do
-   echo offline-online $memory
-   online_memory_expect_success $memory
-done
+hotpluggable_num=`hotpluggable_offline_memory | wc -l`
+echo -e "\t online all hot-pluggable memory in offline state:"
+if [ "$hotpluggable_num" -gt 0 ]; then
+   for memory in `hotpluggable_offline_memory`; do
+ 

[PATCH] selftests: fix memory-hotplug test

2017-06-18 Thread Po-Hsu Lin
Typo correction for hotpluggable_offline_memory() function.
Check for hot-pluggable memory availability in prerequisite().
Check for precentage range for -r flag.

Fix the memory offline test, the $ratio was used with RANDOM as the
possibility to get it offlined, correct it to become the portion of
available removable memory blocks.
Also ask the tool to try to offline the next available memory block
if the attempt is unsuccessful. It will only fail if all removable
memory blocks are busy.

An nice example:
PHLin@Latitude:~$ sudo ./test.sh
Test scope: 10% hotplug memory
 online all hot-pluggable memory in offline state:
SKIPPED - no hot-pluggable memory in offline state
 offline 10% hot-pluggable memory in online state
 trying to offline 3 out of 28 memory block(s):
online->offline memory1
online->offline memory10
./test.sh: line 74: echo: write error: Resource temporarily unavailable
offline_memory_expect_success 10: unexpected fail
online->offline memory100
online->offline memory101
 online all hot-pluggable memory in offline state:
offline->online memory1
offline->online memory100
offline->online memory101
skip extra tests: debugfs is not mounted
PHLin@Latitude:~$ echo $?
0

Signed-off-by: Po-Hsu Lin 
---
 .../selftests/memory-hotplug/mem-on-off-test.sh|   86 +++-
 1 file changed, 67 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh 
b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 6cddde0..f1603e6 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -22,6 +22,11 @@ prerequisite()
echo $msg memory hotplug is not supported >&2
exit 0
fi
+
+   if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
+   echo $msg no hot-pluggable memory >&2
+   exit 0
+   fi
 }
 
 #
@@ -39,7 +44,7 @@ hotpluggable_memory()
done
 }
 
-hotplaggable_offline_memory()
+hotpluggable_offline_memory()
 {
hotpluggable_memory offline
 }
@@ -75,9 +80,12 @@ online_memory_expect_success()
 
if ! online_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2
+   return 1
elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 online_memory_expect_fail()
@@ -86,9 +94,12 @@ online_memory_expect_fail()
 
if online_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2
+   return 1
elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected online >&2
+   return 1
fi
+   return 0
 }
 
 offline_memory_expect_success()
@@ -97,9 +108,12 @@ offline_memory_expect_success()
 
if ! offline_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2
+   return 1
elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 offline_memory_expect_fail()
@@ -108,14 +122,18 @@ offline_memory_expect_fail()
 
if offline_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2
+   return 1
elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2
+   return 1
fi
+   return 0
 }
 
 error=-12
 priority=0
 ratio=10
+retval=0
 
 while getopts e:hp:r: opt; do
case $opt in
@@ -131,6 +149,10 @@ while getopts e:hp:r: opt; do
;;
r)
ratio=$OPTARG
+   if [ "$ratio" -gt 100 ] || [ "$ratio" -lt 0 ]; then
+   echo "The percentage should be an integer within 0~100 
range"
+   exit
+   fi
;;
esac
 done
@@ -143,35 +165,58 @@ fi
 prerequisite
 
 echo "Test scope: $ratio% hotplug memory"
-echo -e "\t online all hotplug memory in offline state"
-echo -e "\t offline $ratio% hotplug memory in online state"
-echo -e "\t online all hotplug memory in offline state"
 
 #
 # Online all hot-pluggable memory
 #
-for memory in `hotplaggable_offline_memory`; do
-   echo offline-online $memory
-   online_memory_expect_success $memory
-done
+hotpluggable_num=`hotpluggable_offline_memory | wc -l`
+echo -e "\t online all hot-pluggable memory in offline state:"
+if [ "$hotpluggable_num" -gt 0 ]; then
+   for memory in `hotpluggable_offline_memory`; do
+   echo "offline->