3
################################################################################
5
# Copyright (c) 2009 FUJITSU LIMITED #
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. #
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 #
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21
# Author: Miao Xie <miaox@cn.fujitsu.com> #
23
################################################################################
25
cd $LTPROOT/testcases/bin
29
export TCID="cpuset01"
36
cpus_all="$(seq -s, 0 $((nr_cpus-1)))"
37
mems_all="$(seq -s, 0 $((nr_mems-1)))"
43
# base_op_write_and_test <write_file_name> <write_string> <expect_string>
44
base_op_write_and_test()
47
local write_string="$2"
48
local expect_string="$3"
52
mkdir -p "$(dirname $write_file)" || {
53
tst_brkm TFAIL "Failed to mkdir -p $(basename $write_file)"
56
[ "$write_string" = NULL ] && write_string=" "
58
/bin/echo "$write_string" > "$write_file" 2> $CPUSET_TMP/stderr
60
write_result="$(cat "$write_file")"
62
case "$expect_string" in
64
test -z "$write_result" -a $ret = 0
71
test "$expect_string" = "$write_result" -a $ret = 0
76
if [ $ret -eq 0 ]; then
77
tst_resm TPASS "$cfile_name: Get the expected string"
79
tst_resm TFAIL "$cfile_name: Test result - $write_result Expected string - \"$expect_string\""
90
base_op_write_and_test "$@"
100
: $((TST_COUNT++)) #BASHISM
106
while read cpus result
108
base_op_test "$CPUSET/1/cpus" "$cpus" "$result"
113
$cpus_all 0-$((nr_cpus-1))
114
${cpus_all}$nr_cpus WRITE_ERROR
117
0-$((nr_cpus-1)) 0-$((nr_cpus-1))
119
0-$nr_cpus WRITE_ERROR
121
0--$((nr_cpus-1)) WRITE_ERROR
122
0,1-$((nr_cpus-2)),$((nr_cpus-1)) 0-$((nr_cpus-1))
123
0,1-$((nr_cpus-2)), 0-$((nr_cpus-2))
127
# while read cpus result
133
while read mems result
135
base_op_test "$CPUSET/1/mems" "$mems" "$result"
140
$mems_all 0-$((nr_mems-1))
141
${mems_all}$nr_mems WRITE_ERROR
144
0-$((nr_mems-1)) 0-$((nr_mems-1))
146
0-$nr_mems WRITE_ERROR
148
0--$((nr_mems-1)) WRITE_ERROR
149
0,1-$((nr_mems-2)),$((nr_mems-1)) 0-$((nr_mems-1))
150
0,1-$((nr_mems-2)), 0-$((nr_mems-2))
154
# while read mems result
159
for filename in cpu_exclusive mem_exclusive mem_hardwall \
160
memory_migrate memory_spread_page memory_spread_slab \
161
sched_load_balance memory_pressure_enabled
163
cfile_name="$filename"
164
while read flags result
166
base_op_test "$CPUSET/$filename" "$flags" "$result"
175
# while read flags, result
176
done # for filename in flagfiles
181
cfile_name="sched_relax_domain_level"
182
while read domain_level result
184
base_op_test "$CPUSET/sched_relax_domain_level" "$domain_level" "$result"
198
# while read domain_level result
201
# attach_task_test <cpus> <mems> <expect>
212
if [ $? -ne 0 ]; then
215
((TST_COUNT++)) #BASHISM
220
mkdir "$CPUSET/sub_cpuset" > /dev/null
221
if [ $? -ne 0 ]; then
224
((TST_COUNT++)) # BASHISM
228
if [ "$cpus" != "NULL" ]; then
229
echo $cpus > "$CPUSET/sub_cpuset/cpus"
231
if [ "$mems" != "NULL" ]; then
232
echo $mems > "$CPUSET/sub_cpuset/mems"
235
cat /dev/zero > /dev/null &
238
# attach task into the cpuset group
239
echo $pid > "$CPUSET/sub_cpuset/tasks" 2> /dev/null
240
if [ $? -eq $expect ]; then
241
tst_resm TPASS "Attaching Task Test successed!!"
243
tst_resm TFAIL "Attaching Task Test failed!! cpus - \"$cpus\", mems - \"$mems\", Expect - \"$expect\", Fact - \"$ret\". (0 - Attach Success, 1 - Attach Fail)"
247
/bin/kill $pid &> /dev/null # BASHISM
249
if [ $? -ne 0 ]; then
252
((TST_COUNT++)) # BASHISM
259
while read cpus mems expect
261
attach_task_test "$cpus" "$mems" "$expect"
267
# while read cpus mems expect
270
test_readonly_cfiles()
272
for filename in cpus mems memory_pressure
274
cfile_name="$filename(READONLY)"
275
base_op_test "$CPUSET/$filename" "0" "WRITE_ERROR"
276
done # for filename in readonly cfiles