All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joerg Vehlow <lkml@jv-coder.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] cpuset_regression_test: Fix for already existing cpusets
Date: Mon, 16 Nov 2020 12:58:29 +0100	[thread overview]
Message-ID: <a42725d1-1469-e71f-e28d-1eff42e3e86d@jv-coder.de> (raw)
In-Reply-To: <20191115101039.43386-1-lkml@jv-coder.de>

Hi,

a ping for this patch? Is something like that (workaround environment 
issues) not wanted in ltp?

Greets
J?rg

On 11/15/2019 11:10 AM, Joerg Vehlow wrote:
> From: Joerg Vehlow <joerg.vehlow@aox-tech.de>
>
> If there are already cpusets defined on the system, that use cpu 0-1,
> the test fails, because it tries to exclusively use cpu 0-1 for the
> testcase.
>
> The fix sets the cpuset for all cgroups to 0 and disables exclusive
> cpu usage for the duration of the test and restores it on cleanup.
> For the test only cpu 1 is set as exclusive. This is enough to
> trigger the bug this regression test was designed for.
> This was tested by reverting the commit mentioned in the testcase.
>
> Signed-off-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
> ---
>   .../cpuset/cpuset_regression_test.sh          | 58 +++++++++++++++++--
>   1 file changed, 54 insertions(+), 4 deletions(-)
>
> diff --git a/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh b/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh
> index dccfd91cd..ed5e30f2a 100755
> --- a/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh
> +++ b/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh
> @@ -26,6 +26,49 @@ TCID=cpuset_regression_test
>   TST_TOTAL=1
>   . test.sh
>   
> +# cpuset_backup_and_update <backup_dir> <what> <value>
> +# Create backup of the values of a specific file (<what>)
> +# in all cpuset groups and set the value to <value>
> +# The backup is written to <backup_dir> in the same structure
> +# as in the cpuset filesystem
> +cpuset_backup_and_update()
> +{
> +	local backup_dir=$1
> +	local what=$2
> +	local value=$3
> +	local old_dir=$(pwd)
> +
> +	cd ${root_cpuset_dir}
> +	find . -mindepth 2 -name ${what} -print0 |
> +	while IFS= read -r -d '' file; do
> +		tst_resm TINFO "Backup ${file} ($(cat "${file}"))"
> +		mkdir -p "$(dirname "${backup_dir}/${file}")"
> +		cat "${file}" > "${backup_dir}/${file}"
> +		echo "${value}" > "${file}"
> +	done
> +
> +	cd ${old_dir}
> +}
> +
> +# cpuset_restore <backup_dir> <what>
> +# Restores the value of a file (<what>) in all cpuset
> +# groups from the backup created by cpuset_backup_and_update
> +cpuset_restore()
> +{
> +	local backup_dir=$1
> +	local what=$2
> +	local old_dir=$(pwd)
> +
> +	cd ${backup_dir}
> +	find . -mindepth 2 -name ${what} -print0 |
> +	while IFS= read -r -d '' file; do
> +		tst_resm TINFO "Restore ${file} ($(cat "${file}"))"
> +		cat "${file}" > "${root_cpuset_dir}/${file}"
> +	done
> +
> +	cd ${old_dir}
> +}
> +
>   setup()
>   {
>   	tst_require_root
> @@ -69,6 +112,10 @@ setup()
>   			       "do not exist."
>   	fi
>   
> +	mkdir cpuset_backup
> +	cpuset_backup_and_update "$(pwd)/cpuset_backup" ${cpu_exclusive} 0
> +	cpuset_backup_and_update "$(pwd)/cpuset_backup" cpuset.cpus 0
> +
>   	cpu_exclusive_value=$(cat ${root_cpuset_dir}/${cpu_exclusive})
>   	if [ "${cpu_exclusive_value}" != "1" ];then
>   		echo 1 > ${root_cpuset_dir}/${cpu_exclusive}
> @@ -86,6 +133,9 @@ cleanup()
>   		rmdir ${root_cpuset_dir}/testdir
>   	fi
>   
> +	cpuset_restore "$(pwd)/cpuset_backup" cpuset.cpus
> +	cpuset_restore "$(pwd)/cpuset_backup" ${cpu_exclusive}
> +
>   	if [ "$cpu_exclusive_value" != 1 ]; then
>   		# Need to flush, or may be output:
>   		# "write error: Device or resource busy"
> @@ -129,15 +179,15 @@ cpuset_test()
>   	fi
>   
>   	# ${cpus} is empty at the begin, that maybe make the system *crash*.
> -	echo 0-1 > ${root_cpuset_dir}/testdir/${cpus}
> +	echo 1 > ${root_cpuset_dir}/testdir/${cpus}
>   	if [ $? -ne 0 ]; then
> -		tst_brkm TFAIL "'echo 0-1 >" \
> +		tst_brkm TFAIL "'echo 1 >" \
>   			       "${root_cpuset_dir}/testdir/${cpus}' failed"
>   	fi
>   
>   	local cpus_value=$(cat ${root_cpuset_dir}/testdir/${cpus})
> -	if [ "${cpus_value}" != "0-1" ]; then
> -		tst_brkm TFAIL "${cpus} is '${cpus_value}', expected '0-1'"
> +	if [ "${cpus_value}" != "1" ]; then
> +		tst_brkm TFAIL "${cpus} is '${cpus_value}', expected '1'"
>   	fi
>   
>   	tst_resm TPASS "Bug is not reproduced"


  reply	other threads:[~2020-11-16 11:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-15 10:10 [LTP] [PATCH] cpuset_regression_test: Fix for already existing cpusets Joerg Vehlow
2020-11-16 11:58 ` Joerg Vehlow [this message]
2020-11-16 14:46   ` Richard Palethorpe
2020-12-04 10:32     ` Joerg Vehlow
2020-12-07 10:41       ` Richard Palethorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a42725d1-1469-e71f-e28d-1eff42e3e86d@jv-coder.de \
    --to=lkml@jv-coder.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.