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