• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/bash
2
3################################################################################
4##                                                                            ##
5## Copyright (c) 2009 FUJITSU LIMITED                                         ##
6##                                                                            ##
7## This program is free software;  you can redistribute it and#or modify      ##
8## it under the terms of the GNU General Public License as published by       ##
9## the Free Software Foundation; either version 2 of the License, or          ##
10## (at your option) any later version.                                        ##
11##                                                                            ##
12## This program is distributed in the hope that it will be useful, but        ##
13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
14## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
15## for more details.                                                          ##
16##                                                                            ##
17## You should have received a copy of the GNU General Public License          ##
18## along with this program;  if not, write to the Free Software               ##
19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
20##                                                                            ##
21## Author: Li Zefan <lizf@cn.fujitsu.com>                                     ##
22##                                                                            ##
23################################################################################
24
25cd $LTPROOT/testcases/bin
26
27export TCID="cgroup_regression_test"
28export TST_TOTAL=10
29export TST_COUNT=1
30
31failed=0
32
33tst_kvercmp 2 6 29
34if [ $? -eq 0 ]; then
35	tst_brkm TCONF ignored "test must be run with kernel 2.6.29 or newer"
36	exit 0
37elif [ ! -f /proc/cgroups ]; then
38	tst_brkm TCONF ignored "Kernel does not support for control groups; skipping testcases";
39	exit 0
40elif [ "x$(id -ru)" != x0 ]; then
41	tst_brkm TCONF ignored "Test must be run as root"
42	exit 0
43fi
44
45dmesg -c > /dev/null
46nr_bug=`dmesg | grep -c "kernel BUG"`
47nr_null=`dmesg | grep -c "kernel NULL pointer dereference"`
48nr_warning=`dmesg | grep -c "^WARNING"`
49nr_lockdep=`dmesg | grep -c "possible recursive locking detected"`
50
51# check_kernel_bug - check if some kind of kernel bug happened
52check_kernel_bug()
53{
54	new_bug=`dmesg | grep -c "kernel BUG"`
55	new_null=`dmesg | grep -c "kernel NULL pointer dereference"`
56	new_warning=`dmesg | grep -c "^WARNING"`
57	new_lockdep=`dmesg | grep -c "possible recursive locking detected"`
58
59	# no kernel bug is detected
60	if [ $new_bug -eq $nr_bug -a $new_warning -eq $nr_warning -a \
61	     $new_null -eq $nr_null -a $new_lockdep -eq $nr_lockdep ]; then
62		return 1
63	fi
64
65	# some kernel bug is detected
66	if [ $new_bug -gt $nr_bug ]; then
67		tst_resm TFAIL "kernel BUG was detected!"
68	fi
69	if [ $new_warning -gt $nr_warning ]; then
70		tst_resm TFAIL "kernel WARNING was detected!"
71	fi
72	if [ $new_null -gt $nr_null ]; then
73		tst_resm TFAIL "kernel NULL pointer dereference!"
74	fi
75	if [ $new_lockdep -gt $nr_lockdep ]; then
76		tst_resm TFAIL "kernel lockdep warning was detected!"
77	fi
78
79	nr_bug=$new_bug
80	nr_null=$new_null
81	nr_warning=$new_warning
82	nr_lockdep=$new_lockdep
83
84	echo "check_kernel_bug found something!"
85	dmesg
86	failed=1
87	return 0
88}
89
90#---------------------------------------------------------------------------
91# Bug:    There was a race when keeping forking processes and at the same
92#         time cat /cgroup/tasks (should be the very first time to read
93#         /cgroup/tasks, otherwise this bug won't be triggered)
94# Kernel: 2.6.24, 2.6.25-rcX
95# Links:  http://lkml.org/lkml/2007/10/17/224
96#         http://lkml.org/lkml/2008/3/5/332
97#         http://lkml.org/lkml/2008/4/16/493
98# Fix:    commit 0e04388f0189fa1f6812a8e1cb6172136eada87e
99#---------------------------------------------------------------------------
100test_1()
101{
102	./fork_processes &
103	sleep 1
104
105	mount -t cgroup -o none,name=foo cgroup cgroup/
106	if [ $? -ne 0 ]; then
107		tst_resm TFAIL "failed to mount cgroup filesystem"
108		failed=1
109		/bin/kill -SIGTERM $!
110		return
111	fi
112	cat cgroup/tasks > /dev/null
113
114	check_kernel_bug
115	if [ $? -eq 1 ]; then
116		tst_resm TPASS "no kernel bug was found"
117	fi
118
119	/bin/kill -SIGTERM $!
120	wait $!
121	umount cgroup/
122}
123
124#---------------------------------------------------------------------------
125# Bug:    a cgroup's notify_on_release flag did not inherit from its parent.
126# Kernel: 2.6.24-rcX
127# Links:  http://lkml.org/lkml/2008/2/25/12
128# Fix:    commit bc231d2a048010d5e0b49ac7fddbfa822fc41109
129#---------------------------------------------------------------------------
130test_2()
131{
132	mount -t cgroup -o none,name=foo cgroup cgroup/
133	if [ $? -ne 0 ]; then
134		tst_resm TFAIL "Failed to mount cgroup filesystem"
135		failed=1
136		return 1
137	fi
138
139	echo 0 > cgroup/notify_on_release
140	mkdir cgroup/0
141	val1=`cat cgroup/0/notify_on_release`
142
143	echo 1 > cgroup/notify_on_release
144	mkdir cgroup/1
145	val2=`cat cgroup/1/notify_on_release`
146
147	if [ $val1 -ne 0 -o $val2 -ne 1 ]; then
148		tst_resm TFAIL "wrong notify_on_release value"
149		failed=1
150	else
151		tst_resm TPASS "notify_on_release is inherited"
152	fi
153
154	rmdir cgroup/0 cgroup/1
155	umount cgroup/
156
157	return $failed
158}
159
160#---------------------------------------------------------------------------
161# Bug:    Accessing NULL cgrp->dentry when reading /proc/sched_debug
162# Kernel: 2.6.26-2.6.28
163# Links:  http://lkml.org/lkml/2008/10/30/44
164#         http://lkml.org/lkml/2008/12/12/107
165#         http://lkml.org/lkml/2008/12/16/481
166# Fix:    commit a47295e6bc42ad35f9c15ac66f598aa24debd4e2
167#---------------------------------------------------------------------------
168test_3()
169{
170	if [ ! -e /proc/sched_debug ]; then
171		tst_resm TCONF "CONFIG_SCHED_DEBUG is not enabled"
172		return
173	fi
174
175	grep -q -w "cpu" /proc/cgroups
176	if [ $? -ne 0 ]; then
177		tst_resm TCONF "CONFIG_CGROUP_SCHED is not enabled"
178		return
179	fi
180
181	# Run the test for 30 secs
182	mount -t cgroup -o cpu xxx cgroup/
183	if [ $? -ne 0 ]; then
184		tst_resm TFAIL "Failed to mount cpu subsys"
185		failed=1
186		return
187	fi
188
189	./test_3_1.sh &
190	pid1=$!
191	./test_3_2.sh &
192	pid2=$!
193
194	sleep 30
195	/bin/kill -SIGUSR1 $pid1 $pid2
196	wait $pid1
197	wait $pid2
198
199	check_kernel_bug
200	if [ $? -eq 1 ]; then
201		tst_resm TPASS "no kernel bug was found"
202	fi
203
204	rmdir cgroup/* 2> /dev/null
205	umount cgroup/
206}
207
208#---------------------------------------------------------------------------
209# Bug:    cgroup hierarchy lock's lockdep subclass may overflow
210# Kernel: 2.6.29-rcX
211# Link:   http://lkml.org/lkml/2009/2/4/67
212# Fix:
213#---------------------------------------------------------------------------
214test_4()
215{
216	if [ ! -e /proc/lockdep ]; then
217		tst_resm TCONF "CONFIG_LOCKDEP is not enabled"
218		return
219	fi
220
221	# MAX_LOCKDEP_SUBCLASSES is 8, so number of subsys should be > 8
222	lines=`cat /proc/cgroups | wc -l`
223	if [ $lines -le 9 ]; then
224		tst_resm TCONF "require more than 8 cgroup subsystems"
225		return
226	fi
227
228	mount -t cgroup -o none,name=foo cgroup cgroup/
229	mkdir cgroup/0
230	rmdir cgroup/0
231	umount cgroup/
232
233	dmesg | grep -q "MAX_LOCKDEP_SUBCLASSES too low"
234	if [ $? -eq 0 ]; then
235		tst_resm TFAIL "lockdep BUG was found"
236		failed=1
237		return
238	else
239		tst_resm TPASS "no lockdep BUG was found"
240	fi
241}
242
243#---------------------------------------------------------------------------
244# Bug:    When mount cgroup fs and the fs was busy, root_count should not be
245#         decremented in cgroup_kill_sb()
246# Kernel: 2.6.29-rcX
247# Links:  https://openvz.org/pipermail/devel/2009-January/016345.html
248#         http://lkml.org/lkml/2009/1/28/190
249# Fix:    commit 839ec5452ebfd5905b9c69b20ceb640903a8ea1a
250#---------------------------------------------------------------------------
251test_5()
252{
253	lines=`cat /proc/cgroups | wc -l`
254	if [ $lines -le 2 ]; then
255		tst_resm TCONF "require at least 2 cgroup subsystems"
256		return
257	fi
258
259	subsys1=`tail -n 1 /proc/cgroups | awk '{ print $1 }'`
260	subsys2=`tail -n 2 /proc/cgroups | head -1 | awk '{ print $1 }'`
261
262	mount -t cgroup -o $subsys1,$subsys2 xxx cgroup/
263	if [ $? -ne 0 ]; then
264		tst_resm TFAIL "mount $subsys1 and $subsys2 failed"
265		failed=1
266		return
267	fi
268
269	# This 2nd mount should fail
270	mount -t cgroup -o $subsys1 xxx cgroup/ 2> /dev/null
271	if [ $? -eq 0 ]; then
272		tst_resm TFAIL "mount $subsys1 should fail"
273		umount cgroup/
274		failed=1
275		return
276	fi
277
278	mkdir cgroup/0
279	# Otherwise we can't attach task
280	if [ "$subsys1" == cpuset -o "$subsys2" == cpuset ]; then
281		echo 0 > cgroup/0/cpuset.cpus 2> /dev/null
282		echo 0 > cgroup/0/cpuset.mems 2> /dev/null
283	fi
284
285	sleep 100 &
286	echo $! > cgroup/0/tasks
287
288	check_kernel_bug
289	if [ $? -eq 1 ]; then
290		tst_resm TPASS "no kernel bug was found"
291	fi
292
293	# clean up
294	/bin/kill -SIGTERM $! > /dev/null
295	wait $!
296	rmdir cgroup/0
297	umount cgroup/
298}
299
300#---------------------------------------------------------------------------
301# Bug:    There was a race between cgroup_clone and umount
302# Kernel: 2.6.24 - 2.6.28, 2.6.29-rcX
303# Links:  http://lkml.org/lkml/2008/12/24/124
304# Fix:    commit 7b574b7b0124ed344911f5d581e9bc2d83bbeb19
305#---------------------------------------------------------------------------
306test_6()
307{
308	grep -q -w "ns" /proc/cgroups
309	if [ $? -ne 0 ]; then
310		tst_resm TCONF "CONFIG_CGROUP_NS"
311		return
312	fi
313
314	# run the test for 30 secs
315	./test_6_1.sh &
316	pid1=$!
317	./test_6_2 &
318	pid2=$!
319
320	sleep 30
321	/bin/kill -SIGUSR1 $pid1
322	/bin/kill -SIGTERM $pid2
323	wait $pid1
324	wait $pid2
325
326	check_kernel_bug
327	if [ $? -eq 1 ]; then
328		tst_resm TPASS "no kernel bug was found"
329	fi
330
331	# clean up
332	mount -t cgroup -o ns xxx cgroup/ > /dev/null 2>&1
333	rmdir cgroup/[1-9]* > /dev/null 2>&1
334	umount cgroup/
335}
336
337#---------------------------------------------------------------------------
338# Bug:    There was a bug when remount cgroup fs with some dead subdirs in
339#         it (rmdir()ed but still has some refcnts on it). It caused memory
340#         leak, and may cause oops when cat /proc/sched_debug.
341# Kernel: 2.6.24 - 2.6.27, 2.6.28-rcX
342# Links:  http://lkml.org/lkml/2008/12/10/369
343# Fix:    commit 307257cf475aac25db30b669987f13d90c934e3a
344#---------------------------------------------------------------------------
345test_7_1()
346{
347	mount -t cgroup -o $subsys xxx cgroup/
348	if [ $? -ne 0 ]; then
349		tst_resm TFAIL "failed to mount $subsys"
350		failed=1
351		return
352	fi
353
354	mkdir cgroup/0
355	sleep 100 < cgroup/0 &	# add refcnt to this dir
356	rmdir cgroup/0
357
358	# remount with new subsystems added
359	# since 2.6.28, this remount will fail
360	mount -t cgroup -o remount xxx cgroup/ 2> /dev/null
361	/bin/kill -SIGTERM $!
362	wait $!
363	umount cgroup/
364}
365
366test_7_2()
367{
368	mount -t cgroup -o none,name=foo cgroup cgroup/
369	if [ $? -ne 0 ]; then
370		tst_resm TFAIL "failed to mount cgroup"
371		failed=1
372		return
373	fi
374
375	mkdir cgroup/0
376	sleep 100 < cgroup/0 &	# add refcnt to this dir
377	rmdir cgroup/0
378
379	# remount with some subsystems removed
380	# since 2.6.28, this remount will fail
381	mount -t cgroup -o remount,$subsys xxx cgroup/ 2> /dev/null
382	/bin/kill -SIGTERM $!
383	wait $!
384	umount cgroup/
385
386	# due to the bug, reading /proc/sched_debug may lead to oops
387	grep -q -w "cpu" /proc/cgroups
388	if [ $? -ne 0 -o ! -e /proc/sched_debug ]; then
389		return
390	fi
391
392	tmp=0
393	while [ $tmp -lt 50 ] ; do
394		echo 3 > /proc/sys/vm/drop_caches
395		cat /proc/sched_debug > /dev/null
396		: $(( tmp += 1 ))
397	done
398}
399
400test_7()
401{
402	lines=`cat /proc/cgroups | wc -l`
403	if [ $lines -le 2 ]; then
404		tst_resm TCONF "require at least 2 cgroup subsystems"
405		slt_result $SLT_Untested
406		return
407	fi
408
409	subsys=`tail -n 1 /proc/cgroups | awk '{ print $1 }'`
410
411	# remount to add new subsystems to the hierarchy
412	i=1
413	while [ $i -le 2 ] ; do
414		test_7_$i
415		if [ $? -ne 0 ]; then
416			return
417		fi
418
419		check_kernel_bug
420		if [ $? -eq 0 ]; then
421			return
422		fi
423		: $(( i += 1 ))
424	done
425
426	tst_resm TPASS "no kernel bug was found"
427}
428
429#---------------------------------------------------------------------------
430# Bug:    oops when get cgroupstat of a cgroup control file
431# Kernel: 2.6.24 - 2.6.27, 2.6.28-rcX
432# Links:  http://lkml.org/lkml/2008/11/19/53
433# Fix:    commit 33d283bef23132c48195eafc21449f8ba88fce6b
434#---------------------------------------------------------------------------
435test_8()
436{
437	mount -t cgroup -o none,name=foo cgroup cgroup/
438	if [ $? -ne 0 ]; then
439		tst_resm TFAIL "failed to mount cgroup filesystem"
440		failed=1
441		return
442	fi
443
444	./getdelays -C cgroup/tasks > /dev/null 2>&1
445	if [ $? -eq 0 ]; then
446		tst_resm TFAIL "should have failed to get cgroupstat of tasks file"
447		umount cgroup/
448		failed=1
449		return
450	fi
451
452	check_kernel_bug
453	if [ $? -eq 1 ]; then
454		tst_resm TPASS "no kernel bug was found"
455	fi
456
457	umount cgroup/
458}
459
460#---------------------------------------------------------------------------
461# Bug:    When running 2 concurrent mount/umount threads, lockdep warning
462#         may be triggered, it's a false positive, and it's VFS' issue but
463#         not cgroup.
464# Kernel: 2.6.24 - 2.6.29-rcX
465# Links:  http://lkml.org/lkml/2009/1/4/352
466# Fix:    commit ada723dcd681e2dffd7d73345cc8fda0eb0df9bd
467#---------------------------------------------------------------------------
468test_9()
469{
470	./test_9_1.sh &
471	pid1=$!
472	./test_9_2.sh &
473	pid2=$!
474
475	sleep 30
476	/bin/kill -SIGUSR1 $pid1 $pid2
477	wait $pid1
478	wait $pid2
479
480	umount cgroup/ 2> /dev/null
481
482	check_kernel_bug
483	if [ $? -eq 1 ]; then
484		tst_resm TPASS "no kernel warning was found"
485	fi
486}
487
488#---------------------------------------------------------------------------
489# Bug:    When running 2 concurrent mount/umount threads, kernel WARNING
490#         may be triggered, but it's VFS' issue but not cgroup.
491# Kernel: 2.6.24 - 2.6.29-rcX
492# Links:  http://lkml.org/lkml/2009/1/4/354
493# Fix:    commit 1a88b5364b535edaa321d70a566e358390ff0872
494#---------------------------------------------------------------------------
495test_10()
496{
497	./test_10_1.sh &
498	pid1=$!
499	./test_10_2.sh &
500	pid2=$!
501
502	sleep 30
503	/bin/kill -SIGUSR1 $pid1 $pid2
504	wait $pid1
505	wait $pid2
506
507	mount -t cgroup none cgroup 2> /dev/null
508	rmdir cgroup/0
509	umount cgroup/
510
511	check_kernel_bug
512	if [ $? -eq 1 ]; then
513		tst_resm TPASS "no kernel warning was found"
514	fi
515}
516
517# main
518
519mkdir cgroup/
520
521for ((cur = 1; cur <= $TST_TOTAL; cur++))
522{
523	export TST_COUNT=$cur
524
525	test_$cur
526}
527
528find cgroup/ -maxdepth 1 -depth -exec rmdir {} +
529
530exit $failed
531