2022-11-13 12:51:11

by Breno Leitao

[permalink] [raw]
Subject: [PATCH] kselftest/cgroup: Fix gathering number of CPUs

test_cpuset_prs.sh is failing with the following error:

test_cpuset_prs.sh: line 29: [[: 8
57%: syntax error in expression (error token is "57%")

This is happening because `lscpu | grep "^CPU(s)"` returns two lines in
some systems (such as Debian unstable):

# lscpu | grep "^CPU(s)"
CPU(s): 8
CPU(s) scaling MHz: 55%

This is a simple fix that discard the second line.

Signed-off-by: Breno Leitao <[email protected]>
---
tools/testing/selftests/cgroup/test_cpuset_prs.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
index 526d2c42d870..564ca8c33035 100755
--- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
+++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
@@ -25,7 +25,7 @@ WAIT_INOTIFY=$(cd $(dirname $0); pwd)/wait_inotify
CGROUP2=$(mount -t cgroup2 | head -1 | awk -e '{print $3}')
[[ -n "$CGROUP2" ]] || skip_test "Cgroup v2 mount point not found!"

-CPUS=$(lscpu | grep "^CPU(s)" | sed -e "s/.*:[[:space:]]*//")
+CPUS=$(lscpu | grep "^CPU(s):" | sed -e "s/.*:[[:space:]]*//")
[[ $CPUS -lt 8 ]] && skip_test "Test needs at least 8 cpus available!"

# Set verbose flag and delay factor
--
2.38.1



2022-11-14 10:13:31

by Kamalesh Babulal

[permalink] [raw]
Subject: Re: [PATCH] kselftest/cgroup: Fix gathering number of CPUs



On 11/13/22 17:14, Breno Leitao wrote:
> test_cpuset_prs.sh is failing with the following error:
>
> test_cpuset_prs.sh: line 29: [[: 8
> 57%: syntax error in expression (error token is "57%")
>
> This is happening because `lscpu | grep "^CPU(s)"` returns two lines in
> some systems (such as Debian unstable):
>
> # lscpu | grep "^CPU(s)"
> CPU(s): 8
> CPU(s) scaling MHz: 55%
>
> This is a simple fix that discard the second line.
>
> Signed-off-by: Breno Leitao <[email protected]>

Tested with util-linux v2.38

Reviewed-by: Kamalesh Babulal <[email protected]>

> ---
> tools/testing/selftests/cgroup/test_cpuset_prs.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> index 526d2c42d870..564ca8c33035 100755
> --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> @@ -25,7 +25,7 @@ WAIT_INOTIFY=$(cd $(dirname $0); pwd)/wait_inotify
> CGROUP2=$(mount -t cgroup2 | head -1 | awk -e '{print $3}')
> [[ -n "$CGROUP2" ]] || skip_test "Cgroup v2 mount point not found!"
>
> -CPUS=$(lscpu | grep "^CPU(s)" | sed -e "s/.*:[[:space:]]*//")
> +CPUS=$(lscpu | grep "^CPU(s):" | sed -e "s/.*:[[:space:]]*//")
> [[ $CPUS -lt 8 ]] && skip_test "Test needs at least 8 cpus available!"
>
> # Set verbose flag and delay factor

--
Thanks,
Kamalesh

2022-11-14 21:59:11

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH] kselftest/cgroup: Fix gathering number of CPUs

On Sun, Nov 13, 2022 at 11:44:49AM +0000, Breno Leitao wrote:
> test_cpuset_prs.sh is failing with the following error:
>
> test_cpuset_prs.sh: line 29: [[: 8
> 57%: syntax error in expression (error token is "57%")
>
> This is happening because `lscpu | grep "^CPU(s)"` returns two lines in
> some systems (such as Debian unstable):
>
> # lscpu | grep "^CPU(s)"
> CPU(s): 8
> CPU(s) scaling MHz: 55%
>
> This is a simple fix that discard the second line.
>
> Signed-off-by: Breno Leitao <[email protected]>

Applied to cgroup/for-6.1-fixes.

Thanks.

--
tejun