diff mbox series

[v3,1/2] cpuset: skip test when cpu or nodes are not numbered continuously from 0

Message ID 1610590728-15813-1-git-send-email-xuyang2018.jy@cn.fujitsu.com
State Accepted
Headers show
Series [v3,1/2] cpuset: skip test when cpu or nodes are not numbered continuously from 0 | expand

Commit Message

Yang Xu Jan. 14, 2021, 2:18 a.m. UTC
These cpuset cases(cpuset_base_ops_test, cpuset_hierarchy_test, cpuset_inherit_test...)
seem all not consider the situation(cpus/memory are not numbered continuously). It is
continuously from 0 as default. Skip test if there are not numbered continuously to
avoid unexpected error.

This patch also fix cpu_inherit error by using original mem value.

cpuset_inherit case fails on 4 numa nodes pc, as below:
cpuset_inherit 1 TPASS: cpus: Inherited information is right!
cpuset_inherit 3 TPASS: cpus: Inherited information is right!
cpuset_inherit 5 TPASS: cpus: Inherited information is right!
cpuset_inherit 7 TPASS: cpus: Inherited information is right!
cpuset_inherit 9 TPASS: cpus: Inherited information is right!
cpuset_inherit 11 TPASS: cpus: Inherited information is right!
cpuset_inherit 13 TPASS: mems: Inherited information is right!
cpuset_inherit 15 TPASS: mems: Inherited information is right!
cpuset_inherit 17 TPASS: mems: Inherited information is right!
cpuset_inherit 19 TPASS: mems: Inherited information is right!
cpuset_inherit 21 TPASS: mems: Inherited information is right!
cpuset_inherit 23 TFAIL: mems: Test result - 0-3 Expected string - "4"

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 .../kernel/controllers/cpuset/cpuset_funcs.sh | 29 +++++++++++++++++--
 1 file changed, 26 insertions(+), 3 deletions(-)

Comments

Yang Xu Jan. 18, 2021, 8:16 a.m. UTC | #1
HI Cyril
ping.

Best Regards
Yang Xu
> These cpuset cases(cpuset_base_ops_test, cpuset_hierarchy_test, cpuset_inherit_test...)
> seem all not consider the situation(cpus/memory are not numbered continuously). It is
> continuously from 0 as default. Skip test if there are not numbered continuously to
> avoid unexpected error.
> 
> This patch also fix cpu_inherit error by using original mem value.
> 
> cpuset_inherit case fails on 4 numa nodes pc, as below:
> cpuset_inherit 1 TPASS: cpus: Inherited information is right!
> cpuset_inherit 3 TPASS: cpus: Inherited information is right!
> cpuset_inherit 5 TPASS: cpus: Inherited information is right!
> cpuset_inherit 7 TPASS: cpus: Inherited information is right!
> cpuset_inherit 9 TPASS: cpus: Inherited information is right!
> cpuset_inherit 11 TPASS: cpus: Inherited information is right!
> cpuset_inherit 13 TPASS: mems: Inherited information is right!
> cpuset_inherit 15 TPASS: mems: Inherited information is right!
> cpuset_inherit 17 TPASS: mems: Inherited information is right!
> cpuset_inherit 19 TPASS: mems: Inherited information is right!
> cpuset_inherit 21 TPASS: mems: Inherited information is right!
> cpuset_inherit 23 TFAIL: mems: Test result - 0-3 Expected string - "4"
> 
> Signed-off-by: Yang Xu<xuyang2018.jy@cn.fujitsu.com>
> ---
>   .../kernel/controllers/cpuset/cpuset_funcs.sh | 29 +++++++++++++++++--
>   1 file changed, 26 insertions(+), 3 deletions(-)
> 
> diff --git a/testcases/kernel/controllers/cpuset/cpuset_funcs.sh b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
> index f4365af2c..84b87d17e 100755
> --- a/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
> +++ b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
> @@ -26,23 +26,34 @@
> 
>   . test.sh
> 
> +cpu_string="`cat /sys/devices/system/cpu/online`"
>   NR_CPUS=`tst_ncpus`
> +
>   if [ -f "/sys/devices/system/node/has_high_memory" ]; then
> -	N_NODES="`cat /sys/devices/system/node/has_high_memory | tr ',' ' '`"
> +	mem_string="`cat /sys/devices/system/node/has_high_memory`"
>   else
> -	N_NODES="`cat /sys/devices/system/node/has_normal_memory | tr ',' ' '`"
> +	mem_string="`cat /sys/devices/system/node/has_normal_memory`"
>   fi
> +N_NODES="`echo $mem_string | tr ',' ' '`"
>   count=0
> +final_node=0
>   for item in $N_NODES; do
>   	delta=1
>   	if [ "${item#*-*}" != "$item" ]; then
>   		delta=$((${item#*-*} - ${item%*-*} + 1))
>   	fi
> +	final_node=${item#*-*}
>   	count=$((count + $delta))
>   done
> +final_node=$((final_node + 1))
>   N_NODES=$count
> 
> -mem_string="$N_NODES"
> +final_cpu=0
> +N_CPUS="`echo $cpu_string | tr ',' ' '`"
> +for item in $N_CPUS; do
> +	final_cpu=${item#*-*}
> +done
> +final_cpu=$((final_cpu + 1))
> 
>   CPUSET="/dev/cpuset"
>   CPUSET_TMP="/tmp/cpuset_tmp"
> @@ -78,6 +89,12 @@ ncpus_check()
>   	if [ $NR_CPUS -lt $1 ]; then
>   		tst_brkm TCONF "The total of CPUs is less than $1"
>   	fi
> +	# check online cpus whether match 0-num
> +	if [ $final_cpu -eq $NR_CPUS ]; then
> +		tst_resm TINFO "CPUs are numbered continuously starting at 0 ($cpu_string)"
> +	else
> +		tst_brkm TCONF "CPUs are not numbered continuously starting at 0 ($cpu_string)"
> +	fi
>   }
> 
>   nnodes_check()
> @@ -85,6 +102,12 @@ nnodes_check()
>   	if [ $N_NODES -lt $1 ]; then
>   		tst_brkm TCONF "The total of nodes is less than $1"
>   	fi
> +	# check online nodes whether match 0-num
> +	if [ $final_node -eq $N_NODES ]; then
> +		tst_resm TINFO "Nodes are numbered continuously starting at 0 ($mem_string)"
> +	else
> +		tst_brkm TCONF "Nodes are not numbered continuously starting at 0 ($mem_string)"
> +	fi
>   }
> 
>   user_check()
Petr Vorel Jan. 19, 2021, 11:21 a.m. UTC | #2
Hi Xu,

> > These cpuset cases(cpuset_base_ops_test, cpuset_hierarchy_test, cpuset_inherit_test...)
> > seem all not consider the situation(cpus/memory are not numbered continuously). It is
> > continuously from 0 as default. Skip test if there are not numbered continuously to
> > avoid unexpected error.

> > This patch also fix cpu_inherit error by using original mem value.

> > cpuset_inherit case fails on 4 numa nodes pc, as below:
> > cpuset_inherit 1 TPASS: cpus: Inherited information is right!
> > cpuset_inherit 3 TPASS: cpus: Inherited information is right!
> > cpuset_inherit 5 TPASS: cpus: Inherited information is right!
> > cpuset_inherit 7 TPASS: cpus: Inherited information is right!
> > cpuset_inherit 9 TPASS: cpus: Inherited information is right!
> > cpuset_inherit 11 TPASS: cpus: Inherited information is right!
> > cpuset_inherit 13 TPASS: mems: Inherited information is right!
> > cpuset_inherit 15 TPASS: mems: Inherited information is right!
> > cpuset_inherit 17 TPASS: mems: Inherited information is right!
> > cpuset_inherit 19 TPASS: mems: Inherited information is right!
> > cpuset_inherit 21 TPASS: mems: Inherited information is right!
> > cpuset_inherit 23 TFAIL: mems: Test result - 0-3 Expected string - "4"

Good catch :).

BTW how this happen? hot-unplug on lpar?
Maybe add brief note about it into commit message.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

...
> > +++ b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
> > @@ -26,23 +26,34 @@

> >   . test.sh

> > +cpu_string="`cat /sys/devices/system/cpu/online`"
> >   NR_CPUS=`tst_ncpus`
> > +
> >   if [ -f "/sys/devices/system/node/has_high_memory" ]; then
> > -	N_NODES="`cat /sys/devices/system/node/has_high_memory | tr ',' ' '`"
> > +	mem_string="`cat /sys/devices/system/node/has_high_memory`"
> >   else
> > -	N_NODES="`cat /sys/devices/system/node/has_normal_memory | tr ',' ' '`"
> > +	mem_string="`cat /sys/devices/system/node/has_normal_memory`"
> >   fi
> > +N_NODES="`echo $mem_string | tr ',' ' '`"

nit: I'd personally do:

f="/sys/devices/system/node/has_high_memory"
[ -f "$f" ] || f="/sys/devices/system/node/has_normal_memory"
N_NODES="$(cat $f | tr ',' ' ')"

but that's a tiny detail.

It'd be great to rewrite these tests into C.

Kind regards,
Petr
Cyril Hrubis Jan. 19, 2021, 11:50 a.m. UTC | #3
Hi!
Looks good to me as well.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Yang Xu Jan. 20, 2021, 1:45 a.m. UTC | #4
Hi Petr
> Hi Xu,
>
>>> These cpuset cases(cpuset_base_ops_test, cpuset_hierarchy_test, cpuset_inherit_test...)
>>> seem all not consider the situation(cpus/memory are not numbered continuously). It is
>>> continuously from 0 as default. Skip test if there are not numbered continuously to
>>> avoid unexpected error.
>
>>> This patch also fix cpu_inherit error by using original mem value.
>
>>> cpuset_inherit case fails on 4 numa nodes pc, as below:
>>> cpuset_inherit 1 TPASS: cpus: Inherited information is right!
>>> cpuset_inherit 3 TPASS: cpus: Inherited information is right!
>>> cpuset_inherit 5 TPASS: cpus: Inherited information is right!
>>> cpuset_inherit 7 TPASS: cpus: Inherited information is right!
>>> cpuset_inherit 9 TPASS: cpus: Inherited information is right!
>>> cpuset_inherit 11 TPASS: cpus: Inherited information is right!
>>> cpuset_inherit 13 TPASS: mems: Inherited information is right!
>>> cpuset_inherit 15 TPASS: mems: Inherited information is right!
>>> cpuset_inherit 17 TPASS: mems: Inherited information is right!
>>> cpuset_inherit 19 TPASS: mems: Inherited information is right!
>>> cpuset_inherit 21 TPASS: mems: Inherited information is right!
>>> cpuset_inherit 23 TFAIL: mems: Test result - 0-3 Expected string - "4"
>
> Good catch :).
>
> BTW how this happen? hot-unplug on lpar?
> Maybe add brief note about it into commit message.
I have added it and merged this patchset, thanks for you and cyril's review.
>
> Reviewed-by: Petr Vorel<pvorel@suse.cz>
>
> ...
>>> +++ b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
>>> @@ -26,23 +26,34 @@
>
>>>    . test.sh
>
>>> +cpu_string="`cat /sys/devices/system/cpu/online`"
>>>    NR_CPUS=`tst_ncpus`
>>> +
>>>    if [ -f "/sys/devices/system/node/has_high_memory" ]; then
>>> -	N_NODES="`cat /sys/devices/system/node/has_high_memory | tr ',' ' '`"
>>> +	mem_string="`cat /sys/devices/system/node/has_high_memory`"
>>>    else
>>> -	N_NODES="`cat /sys/devices/system/node/has_normal_memory | tr ',' ' '`"
>>> +	mem_string="`cat /sys/devices/system/node/has_normal_memory`"
>>>    fi
>>> +N_NODES="`echo $mem_string | tr ',' ' '`"
>
> nit: I'd personally do:
>
> f="/sys/devices/system/node/has_high_memory"
> [ -f "$f" ] || f="/sys/devices/system/node/has_normal_memory"
> N_NODES="$(cat $f | tr ',' ' ')"
>
> but that's a tiny detail.
>
> It'd be great to rewrite these tests into C.
Yes, I will create a issue to avoid we forget this.
>
> Kind regards,
> Petr
>
>
> .
>
diff mbox series

Patch

diff --git a/testcases/kernel/controllers/cpuset/cpuset_funcs.sh b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
index f4365af2c..84b87d17e 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
@@ -26,23 +26,34 @@ 
 
 . test.sh
 
+cpu_string="`cat /sys/devices/system/cpu/online`"
 NR_CPUS=`tst_ncpus`
+
 if [ -f "/sys/devices/system/node/has_high_memory" ]; then
-	N_NODES="`cat /sys/devices/system/node/has_high_memory | tr ',' ' '`"
+	mem_string="`cat /sys/devices/system/node/has_high_memory`"
 else
-	N_NODES="`cat /sys/devices/system/node/has_normal_memory | tr ',' ' '`"
+	mem_string="`cat /sys/devices/system/node/has_normal_memory`"
 fi
+N_NODES="`echo $mem_string | tr ',' ' '`"
 count=0
+final_node=0
 for item in $N_NODES; do
 	delta=1
 	if [ "${item#*-*}" != "$item" ]; then
 		delta=$((${item#*-*} - ${item%*-*} + 1))
 	fi
+	final_node=${item#*-*}
 	count=$((count + $delta))
 done
+final_node=$((final_node + 1))
 N_NODES=$count
 
-mem_string="$N_NODES"
+final_cpu=0
+N_CPUS="`echo $cpu_string | tr ',' ' '`"
+for item in $N_CPUS; do
+	final_cpu=${item#*-*}
+done
+final_cpu=$((final_cpu + 1))
 
 CPUSET="/dev/cpuset"
 CPUSET_TMP="/tmp/cpuset_tmp"
@@ -78,6 +89,12 @@  ncpus_check()
 	if [ $NR_CPUS -lt $1 ]; then
 		tst_brkm TCONF "The total of CPUs is less than $1"
 	fi
+	# check online cpus whether match 0-num
+	if [ $final_cpu -eq $NR_CPUS ]; then
+		tst_resm TINFO "CPUs are numbered continuously starting at 0 ($cpu_string)"
+	else
+		tst_brkm TCONF "CPUs are not numbered continuously starting at 0 ($cpu_string)"
+	fi
 }
 
 nnodes_check()
@@ -85,6 +102,12 @@  nnodes_check()
 	if [ $N_NODES -lt $1 ]; then
 		tst_brkm TCONF "The total of nodes is less than $1"
 	fi
+	# check online nodes whether match 0-num
+	if [ $final_node -eq $N_NODES ]; then
+		tst_resm TINFO "Nodes are numbered continuously starting at 0 ($mem_string)"
+	else
+		tst_brkm TCONF "Nodes are not numbered continuously starting at 0 ($mem_string)"
+	fi
 }
 
 user_check()