1#!/bin/sh
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: Miao Xie <[email protected]>                                      #
22#                                                                              #
23################################################################################
24
25export TCID="cpuset_inherit"
26export TST_TOTAL=33
27export TST_COUNT=1
28
29. cpuset_funcs.sh
30
31check 1 1
32
33nr_cpus=$NR_CPUS
34nr_mems=$N_NODES
35
36cpus_all="$(seq -s, 0 $((nr_cpus-1)))"
37mems_all="$(seq -s, 0 $((nr_mems-1)))"
38
39exit_status=0
40
41cfile_name=
42
43# base_op_write_and_test <write_file_name> <write_string> <expect_string>
44base_op_write_and_test()
45{
46	local write_file="$1"
47	local inherit_value="$2"
48	local write_string="$3"
49	local expect_string="$4"
50	local return_result=
51
52	echo $inherit_value > $CLONE_CHILDREN
53
54	mkdir -p "$(dirname $write_file)" || {
55		tst_brkm TFAIL "Failed to mkdir -p $(basename $write_file)"
56		return 1
57	}
58	[ "$write_string" = NULL ] && write_string=" "
59
60	/bin/echo "$write_string" > "$write_file" 2> $CPUSET_TMP/stderr
61	mkdir $(dirname $write_file)/2 2> $CPUSET_TMP/stderr
62	return_result=$?
63	write_result="$(cat "$(dirname $write_file)/2/$(basename $write_file)")"
64
65	case "$expect_string" in
66	EMPTY)
67		test -z "$write_result" -a $return_result = 0
68		return_result=$?
69		;;
70	WRITE_ERROR)
71		return_result=$((!$return_result))
72		;;
73	*)
74		test "$expect_string" = "$write_result" -a $return_result = 0
75		return_result=$?
76		;;
77	esac
78
79	if [ $return_result -eq 0 ]; then
80		tst_resm TPASS "$cfile_name: Inherited information is right!"
81        else
82		tst_resm TFAIL "$cfile_name: Test result - $write_result Expected string - \"$expect_string\""
83        fi
84        return $return_result
85}
86
87inherit_test()
88{
89	setup
90	if [ $? -ne 0 ]; then
91		exit_status=1
92	else
93		base_op_write_and_test "$@"
94		if [ $? -ne 0 ]; then
95			exit_status=1
96		fi
97
98		cleanup
99		if [ $? -ne 0 ]; then
100			exit_status=1
101		fi
102	fi
103	TST_COUNT=$(($TST_COUNT + 1))
104}
105
106test_cpus()
107{
108	cfile_name="cpus"
109	while read inherit cpus result
110	do
111		inherit_test "$CPUSET/1/cpuset.cpus" "$inherit" "$cpus" "$result"
112	done <<- EOF
113		0	NULL					EMPTY
114		0	0					EMPTY
115		0	$cpus_all				EMPTY
116		1	NULL					EMPTY
117		1	0					0
118		1	$cpus_all				$cpu_string
119	EOF
120	# while read cpus result
121}
122
123test_mems()
124{
125	cfile_name="mems"
126	while read inherit mems result
127	do
128		inherit_test "$CPUSET/1/cpuset.mems" "$inherit" "$mems" "$result"
129	done <<- EOF
130		0	NULL					EMPTY
131		0	0					EMPTY
132		0	$mems_all				EMPTY
133		1	NULL					EMPTY
134		1	0					0
135		1	$mems_all				$mem_string
136	EOF
137	# while read mems result
138}
139
140# test cpu_exclusive mem_exclusive mem_hardwall memory_migrate
141test_three_result_similar_flags()
142{
143	for filename in cpu_exclusive mem_exclusive mem_hardwall \
144			memory_migrate
145	do
146		cfile_name="$filename"
147		while read inherit flags result
148		do
149			inherit_test "$CPUSET/1/cpuset.$filename" "$inherit" "$flags" "$result"
150		done <<- EOF
151			0	0	0
152			0	1	0
153		EOF
154		# while read flags, result
155	done # for filename in flagfiles
156}
157
158# test memory_spread_page memory_spread_slab
159test_spread_flags()
160{
161	for filename in memory_spread_page memory_spread_slab
162	do
163		cfile_name="$filename"
164		while read inherit flags result
165		do
166			inherit_test "$CPUSET/1/cpuset.$filename" "$inherit" "$flags" "$result"
167		done <<- EOF
168			0	0	0
169			0	1	1
170		EOF
171		# while read flags, result
172	done # for filename in flagfiles
173}
174
175test_sched_load_balance_flag()
176{
177	cfile_name="sched_load_balance"
178	while read inherit flag result
179	do
180		inherit_test "$CPUSET/1/cpuset.sched_load_balance" "$inherit" "$flag" "$result"
181	done <<- EOF
182		0	0	1
183		0	1	1
184	EOF
185	# while read mems result
186}
187
188test_domain()
189{
190	cfile_name="sched_relax_domain_level"
191	while read inherit domain_level result
192	do
193		inherit_test "$CPUSET/1/cpuset.sched_relax_domain_level" "$inherit" "$domain_level" "$result"
194	done <<- EOF
195		0	-1	-1
196		0	0	-1
197		0	1	-1
198		0	2	-1
199		0	3	-1
200		0	4	-1
201		0	5	-1
202	EOF
203	# while read domain_level result
204}
205
206# Case 1-6
207test_cpus
208
209# Case 7-12
210test_mems
211
212# Case 13-20
213test_three_result_similar_flags
214
215# Case 21-24
216test_spread_flags
217
218# Case 25-26
219test_sched_load_balance_flag
220
221# Case 27-33
222test_domain
223
224exit $exit_status
225