Skip to contentSkip to conversation

cpuset: regression test for "system crash if cpuset_cpumask_can_shrink() is passed an empty cpumask"

PATCH In review Zeng Linggang 2 participants 4 messages May 26, 2015 – Jul 30, 2015 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuset: regression test for "system crash if cpuset_cpumask_can_shrink() is passed an empty cpumask"

This fixed by:
commit bb2bc55a694d45cdeda91b6f28ab2adec28125ef

Author: Mike Galbraith <[email protected]>
Date:   Wed Jan 28 04:53:55 2015 +0100

sched: Fix crash if cpuset_cpumask_can_shrink() is passed an empty cpumask

---
 .../controllers/cpuset/cpuset_regression_test.sh   | 146 +++++++++++++++++++++
 1 file changed, 146 insertions(+)
 create mode 100755 testcases/kernel/controllers/cpuset/cpuset_regression_test.sh
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +146 -0
new file mode 100755
index 0000000..fa06326
@@ -0,0 +1,146 @@
+#!/bin/sh
+#
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author: Zeng Linggang <[email protected]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# This is a regression test for commit:
+# http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/
+# ?id=bb2bc55
+#
+
+TCID=cpuset_regression_test
+TST_TOTAL=1
+. test.sh
+
+setup()
+{
+	tst_require_root
+
+	tst_kvercmp 3 18 0
+	if [ $? -eq 0 ]; then
+		tst_brkm TCONF "Test must be run with kernel 3.18.0 or newer"
+	fi
+
+	local cpu_num=$(grep processor /proc/cpuinfo | wc -l)
+	if [ $cpu_num -lt 2 ]; then
+		tst_brkm TCONF "We need 2 cpus at least to have test"
+	fi
+
+	tst_tmpdir
+}
+
+setup1()
+{
+	# We need to mount cpuset if it is not found.
+	mount_flag=0
+	mount | grep -w cpuset > tmpfile
+	if [ $? -eq 0 ]; then
+		root_cpuset_dir=$(cat tmpfile | awk '{print $3}')
+		rm -rf tmpfile
+	else
+		root_cpuset_dir="cpuset_test"
+
+		ROD_SILENT mkdir -p ${root_cpuset_dir}
+
+		ROD_SILENT mount -t cpuset cpuset ${root_cpuset_dir}
+
+		mount_flag=1
+	fi
+
+	if [ -f ${root_cpuset_dir}/cpuset.cpu_exclusive ]; then
+		cpu_exclusive=cpuset.cpu_exclusive
+		cpus=cpuset.cpus
+	elif [ -f ${root_cpuset_dir}/cpu_exclusive ]; then
+		cpu_exclusive=cpu_exclusive
+		cpus=cpus
+	else
+		tst_brkm TBROK "Both cpuset.cpu_exclusive and cpu_exclusive" \
+			       "do not exist."
+	fi
+
+	local cpu_exclusive_value=$(cat ${root_cpuset_dir}/${cpu_exclusive})
+	if [ "${cpu_exclusive_value}" != "1" ];then
+		echo 1 > ${root_cpuset_dir}/${cpu_exclusive}
+		if [ $? -ne 0 ]; then
+			tst_brkm TBROK "'echo 1 >" \
+				       "${root_cpuset_dir}/${cpu_exclusive}'" \
+				       "failed"
+		fi
+	fi
+}
+
+cleanup()
+{
+	if [ -d "${root_cpuset_dir}/testdir" ]; then
+		rmdir ${root_cpuset_dir}/testdir
+	fi
+
+	if [ "${mount_flag}" == "1" ]; then
+		umount ${root_cpuset_dir}
+		if [ $? -ne 0 ]; then
+			tst_resm TWARN "umount ${root_cpuset_dir} failed"
+		fi
+
+		if [ -d "${root_cpuset_dir}" ]; then
+			rmdir ${root_cpuset_dir}
+		fi
+	fi
+
+	tst_rmdir
+}
+
+cpuset_test()
+{
+	ROD_SILENT mkdir ${root_cpuset_dir}/testdir
+
+	# Creat an exclusive cpuset.
+	echo 1 > ${root_cpuset_dir}/testdir/${cpu_exclusive}
+	if [ $? -ne 0 ]; then
+		tst_brkm TFAIL "'echo 1 >" \
+			       "${root_cpuset_dir}/testdir/${cpu_exclusive}'" \
+			       "failed"
+	fi
+
+	local cpu_exclusive_value=$(cat \
+				    ${root_cpuset_dir}/testdir/${cpu_exclusive})
+	if [ "${cpu_exclusive_value}" != "1" ]; then
+		tst_brkm TFAIL "${cpu_exclusive} is '${cpu_exclusive_value}'," \
+			       "expected '1'"
+	fi
+
+	# ${cpus} is empty at the begin, that maybe make the system *crash*.
+	echo 0-1 > ${root_cpuset_dir}/testdir/${cpus}
+	if [ $? -ne 0 ]; then
+		tst_brkm TFAIL "'echo 0-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'"
+	fi
+
+	tst_resm TPASS "Bug is not reproduced"
+}
+
+setup
+TST_CLEANUP=cleanup
+
+setup1
+cpuset_test
+
+tst_exit
Signature · 15 lines
1.8.3.1




------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!

Quoted 4 lines
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +4 -0
+TCID=cpuset_regression_test
+TST_TOTAL=1
+. test.sh
+

testcases/kernel/controllers/cpuset/cpuset_regression_test.sh line 38

Quoted 10 lines
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +10 -0
+setup()
+{
+	tst_require_root
+
+	tst_kvercmp 3 18 0
+	if [ $? -eq 0 ]; then
+		tst_brkm TCONF "Test must be run with kernel 3.18.0 or newer"
+	fi
+
+	local cpu_num=$(grep processor /proc/cpuinfo | wc -l)

It's better to use $(getconf _NPROCESSORS_ONLN)

Quoted 35 lines
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +35 -0
+	if [ $cpu_num -lt 2 ]; then
+		tst_brkm TCONF "We need 2 cpus at least to have test"
+	fi
+
+	tst_tmpdir
+}
+
+setup1()
+{
+	# We need to mount cpuset if it is not found.
+	mount_flag=0
+	mount | grep -w cpuset > tmpfile
+	if [ $? -eq 0 ]; then
+		root_cpuset_dir=$(cat tmpfile | awk '{print $3}')
+		rm -rf tmpfile
+	else
+		root_cpuset_dir="cpuset_test"
+
+		ROD_SILENT mkdir -p ${root_cpuset_dir}
+
+		ROD_SILENT mount -t cpuset cpuset ${root_cpuset_dir}
+
+		mount_flag=1
+	fi
+
+	if [ -f ${root_cpuset_dir}/cpuset.cpu_exclusive ]; then
+		cpu_exclusive=cpuset.cpu_exclusive
+		cpus=cpuset.cpus
+	elif [ -f ${root_cpuset_dir}/cpu_exclusive ]; then
+		cpu_exclusive=cpu_exclusive
+		cpus=cpus
+	else
+		tst_brkm TBROK "Both cpuset.cpu_exclusive and cpu_exclusive" \
+			       "do not exist."
+	fi

testcases/kernel/controllers/cpuset/cpuset_regression_test.sh line 83

Quoted 10 lines
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +10 -0
+
+	local cpu_exclusive_value=$(cat ${root_cpuset_dir}/${cpu_exclusive})
+	if [ "${cpu_exclusive_value}" != "1" ];then
+		echo 1 > ${root_cpuset_dir}/${cpu_exclusive}
+		if [ $? -ne 0 ]; then
+			tst_brkm TBROK "'echo 1 >" \
+				       "${root_cpuset_dir}/${cpu_exclusive}'" \
+				       "failed"
+		fi
+	fi

You should restore the cpu_exclusive value in the cpuset root at the end of the test as well.

i.e. make this variable global and do:

if [ -n "$cpu_exclusive_value" ]; then

	echo "$cpu_exclusive_value" > ${root_cpuset_dir}/${cpu_exclusive}

fi

in the cleanup.

Quoted 50 lines
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +50 -0
+}
+
+cleanup()
+{
+	if [ -d "${root_cpuset_dir}/testdir" ]; then
+		rmdir ${root_cpuset_dir}/testdir
+	fi
+
+	if [ "${mount_flag}" == "1" ]; then
+		umount ${root_cpuset_dir}
+		if [ $? -ne 0 ]; then
+			tst_resm TWARN "umount ${root_cpuset_dir} failed"
+		fi
+
+		if [ -d "${root_cpuset_dir}" ]; then
+			rmdir ${root_cpuset_dir}
+		fi
+	fi
+
+	tst_rmdir
+}
+
+cpuset_test()
+{
+	ROD_SILENT mkdir ${root_cpuset_dir}/testdir
+
+	# Creat an exclusive cpuset.
+	echo 1 > ${root_cpuset_dir}/testdir/${cpu_exclusive}
+	if [ $? -ne 0 ]; then
+		tst_brkm TFAIL "'echo 1 >" \
+			       "${root_cpuset_dir}/testdir/${cpu_exclusive}'" \
+			       "failed"
+	fi
+
+	local cpu_exclusive_value=$(cat \
+				    ${root_cpuset_dir}/testdir/${cpu_exclusive})
+	if [ "${cpu_exclusive_value}" != "1" ]; then
+		tst_brkm TFAIL "${cpu_exclusive} is '${cpu_exclusive_value}'," \
+			       "expected '1'"
+	fi
+
+	# ${cpus} is empty at the begin, that maybe make the system *crash*.
+	echo 0-1 > ${root_cpuset_dir}/testdir/${cpus}
+	if [ $? -ne 0 ]; then
+		tst_brkm TFAIL "'echo 0-1 >" \
+			       "${root_cpuset_dir}/testdir/${cpus}' failed"
+	fi
+
+	local cpus_value=$(cat ${root_cpuset_dir}/testdir/${cpus})
+	if [ "${cpus_value}" != "0-1" ]; then

testcases/kernel/controllers/cpuset/cpuset_regression_test.sh line 143

Quoted 10 lines
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +10 -0
+		tst_brkm TFAIL "${cpus} is '${cpus_value}', expected '0-1'"
+	fi
+
+	tst_resm TPASS "Bug is not reproduced"
+}
+
+setup
+TST_CLEANUP=cleanup
+
+setup1

Hmm, you can set TST_CLEANUP in the middle of the setup() function. There is no need to artificially split the setup.

Quoted 19 lines
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +3 -0
+cpuset_test
+
+tst_exit
Signature · 15 lines
1.8.3.1




------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Signature · 8 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#3 lore raw
In reply to a message not in the archive

Hi!

Quoted 6 lines

This fixed by:
commit bb2bc55a694d45cdeda91b6f28ab2adec28125ef

Author: Mike Galbraith <[email protected]>
Date:   Wed Jan 28 04:53:55 2015 +0100

sched: Fix crash if cpuset_cpumask_can_shrink() is passed an empty cpumask

This one looks good but we should add runtest entry too, runtest/controllers looks like the right one to me.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw
In reply to a message not in the archive

Hi!

Quoted 15 lines
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +15 -0
+cleanup()
+{
+	if [ -d "${root_cpuset_dir}/testdir" ]; then
+		rmdir ${root_cpuset_dir}/testdir
+	fi
+
+	if [ "${mount_flag}" == "1" ]; then
+		umount ${root_cpuset_dir}
+		if [ $? -ne 0 ]; then
+			tst_resm TWARN "'umount ${root_cpuset_dir}' failed"
+		fi
+
+		if [ -d "${root_cpuset_dir}" ]; then
+			rmdir ${root_cpuset_dir}
+		fi

testcases/kernel/controllers/cpuset/cpuset_regression_test.sh line 116

Quoted 10 lines
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh new file +10 -0
+	fi
+
+	if [ -n ${cpu_exclusive_value} -a ${cpu_exclusive_value} -ne 1 ]; then
+		# Need to flush, or may be output:
+		# "write error: Device or resource busy"
+		sync
+
+		echo ${cpu_exclusive_value} > \
+		     ${root_cpuset_dir}/${cpu_exclusive}
+	fi

I've moved the cpu_exclusive restoration before the umount above (since we need to do the steps from setup in reverse order here) and pushed, thanks.

Signature · 8 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list