summaryrefslogtreecommitdiffstats
path: root/test/bashisms/unknown-fns.sh
blob: 64d1b46dde7d566b7ed604860300e55ba9fe38c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/bin/sh

################################################################################
#                                                                              #
# Copyright (c) 2009 FUJITSU LIMITED                                           #
#                                                                              #
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA      #
#                                                                              #
# Author: Miao Xie <miaox@cn.fujitsu.com>                                      #
#                                                                              #
################################################################################

cd $LTPROOT/testcases/bin

. ./cpuset_funcs.sh

export TCID="cpuset01"
export TST_TOTAL=97
export TST_COUNT=1

nr_cpus=$NR_CPUS
nr_mems=$N_NODES

cpus_all="$(seq -s, 0 $((nr_cpus-1)))"
mems_all="$(seq -s, 0 $((nr_mems-1)))"

exit_status=0

cfile_name=

# base_op_write_and_test <write_file_name> <write_string> <expect_string>
base_op_write_and_test()
{
	local write_file="$1"
	local write_string="$2"
	local expect_string="$3"
	local write_result=
	local ret=0

	mkdir -p "$(dirname $write_file)" || {
		tst_brkm TFAIL "Failed to mkdir -p $(basename $write_file)"
		return 1
	}
	[ "$write_string" = NULL ] && write_string=" "
	
	/bin/echo "$write_string" > "$write_file" 2> $CPUSET_TMP/stderr
	ret=$?
	write_result="$(cat "$write_file")"
	
	case "$expect_string" in
	EMPTY)
		test -z "$write_result" -a $ret = 0
		ret=$?
		;;
	WRITE_ERROR)
		ret=$((!$ret))
		;;
	*)
		test "$expect_string" = "$write_result" -a $ret = 0
		ret=$?
		;;
	esac

	if [ $ret -eq 0 ]; then
		tst_resm TPASS "$cfile_name: Get the expected string"
	else
		tst_resm TFAIL "$cfile_name: Test result - $write_result Expected string - \"$expect_string\""
	fi
	return $ret
}

base_op_test()
{
	setup
	if [ $? -ne 0 ]; then
		exit_status=1
	else
		base_op_write_and_test "$@"
		if [ $? -ne 0 ]; then
			exit_status=1
		fi

		cleanup
		if [ $? -ne 0 ]; then
			exit_status=1
		fi
	fi
	: $((TST_COUNT++)) #BASHISM
}

test_cpus()
{
	cfile_name="cpus"
	while read cpus result
	do
		base_op_test "$CPUSET/1/cpus" "$cpus" "$result"
	done <<- EOF
		NULL					EMPTY
		0					0
		$nr_cpus				WRITE_ERROR
		$cpus_all				0-$((nr_cpus-1))
		${cpus_all}$nr_cpus			WRITE_ERROR
		0,0					0
		0-0					0
		0-$((nr_cpus-1))			0-$((nr_cpus-1))
		-1					WRITE_ERROR
		0-$nr_cpus				WRITE_ERROR
		0-					WRITE_ERROR
		0--$((nr_cpus-1))			WRITE_ERROR
		0,1-$((nr_cpus-2)),$((nr_cpus-1))	0-$((nr_cpus-1))
		0,1-$((nr_cpus-2)),			0-$((nr_cpus-2))
		0AAA					WRITE_ERROR
		AAA					WRITE_ERROR
	EOF
	# while read cpus result
}

test_mems()
{
	cfile_name="mems"
	while read mems result
	do
		base_op_test "$CPUSET/1/mems" "$mems" "$result"
	done <<- EOF
		NULL					EMPTY
		0					0
		$nr_mems				WRITE_ERROR
		$mems_all				0-$((nr_mems-1))
		${mems_all}$nr_mems			WRITE_ERROR
		0,0					0
		0-0					0
		0-$((nr_mems-1))			0-$((nr_mems-1))
		-1					WRITE_ERROR
		0-$nr_mems				WRITE_ERROR
		0-					WRITE_ERROR
		0--$((nr_mems-1))			WRITE_ERROR
		0,1-$((nr_mems-2)),$((nr_mems-1))	0-$((nr_mems-1))
		0,1-$((nr_mems-2)),			0-$((nr_mems-2))
		0AAA					WRITE_ERROR
		AAA					WRITE_ERROR
	EOF
	# while read mems result
}

test_flags()
{
	for filename in cpu_exclusive mem_exclusive mem_hardwall \
			memory_migrate memory_spread_page memory_spread_slab \
			sched_load_balance memory_pressure_enabled
	do
		cfile_name="$filename"
		while read flags result
		do
			base_op_test "$CPUSET/$filename" "$flags" "$result"
		done <<- EOF
			NULL	0
			0	0
			1	1
			-1	WRITE_ERROR
			A	WRITE_ERROR
			2	1
		EOF
		# while read flags, result
	done # for filename in flagfiles
}

test_domain()
{
	cfile_name="sched_relax_domain_level"
	while read domain_level result
	do
		base_op_test "$CPUSET/sched_relax_domain_level" "$domain_level" "$result"
	done <<- EOF
		NULL	0
		0	0
		1	1
		2	2
		3	3
		4	4
		5	5
		6	WRITE_ERROR
		-1	-1
		-2	WRITE_ERROR
		A	WRITE_ERROR
	EOF
	# while read domain_level result
}

# attach_task_test <cpus> <mems> <expect>
attach_task_test()
{
	local cpus=$1
	local mems=$2
	local expect=$3

	local pid=
	local ret=

	setup
	if [ $? -ne 0 ]; then
		exit_status=1
		cleanup
		((TST_COUNT++)) #BASHISM
		return
	fi

	# create sub cpuset
	mkdir "$CPUSET/sub_cpuset" > /dev/null
	if [ $? -ne 0 ]; then
		exit_status=1
		cleanup
		((TST_COUNT++)) # BASHISM
		return
	fi

	if [ "$cpus" != "NULL" ]; then
		echo $cpus > "$CPUSET/sub_cpuset/cpus"
	fi
	if [ "$mems" != "NULL" ]; then
		echo $mems > "$CPUSET/sub_cpuset/mems"
	fi

	cat /dev/zero > /dev/null &
	pid=$!

	# attach task into the cpuset group
	echo $pid > "$CPUSET/sub_cpuset/tasks" 2> /dev/null
	if [ $? -eq $expect ]; then
		tst_resm TPASS "Attaching Task Test successed!!"
	else
		tst_resm TFAIL "Attaching Task Test failed!! cpus - \"$cpus\", mems - \"$mems\", Expect - \"$expect\", Fact - \"$ret\". (0 - Attach Success, 1 - Attach Fail)"
		exit_status=1
	fi

	/bin/kill $pid &> /dev/null # BASHISM
	cleanup
	if [ $? -ne 0 ]; then
		exit_status=1
	fi
	((TST_COUNT++)) # BASHISM
}


test_attach_task()
{
	cfile_name="tasks"
	while read cpus mems expect
	do
		attach_task_test "$cpus" "$mems" "$expect"
	done <<- EOF
		0	NULL	1
		0	0	0
		NULL	0	1
	EOF
	# while read cpus mems expect
}

test_readonly_cfiles()
{
	for filename in cpus mems memory_pressure
	do
		cfile_name="$filename(READONLY)"
		base_op_test "$CPUSET/$filename" "0" "WRITE_ERROR"
	done # for filename in readonly cfiles
}

# Case 1-3
test_readonly_cfiles

# Case 4-19
test_cpus

# Case 20-35
test_mems

# Case 36-83
test_flags

# Case 84-94
test_domain

# Case 95-97
test_attach_task

exit $exit_status