cpuset_memory_testset.sh revision 27f2cc5998cd63a26a3c3d679bd1dec40cf741e7
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
25cd $LTPROOT/testcases/bin
26
27export TCID="cpuset09"
28export TST_TOTAL=18
29export TST_COUNT=1
30
31. ./cpuset_funcs.sh
32
33exit_status=0
34
35# must >= 3 for: 1-$((nr_mems-2))
36nr_cpus=4
37nr_mems=3
38
39cpus_all="$(seq -s, 0 $((nr_cpus-1)))"
40mems_all="$(seq -s, 0 $((nr_mems-1)))"
41
42cpu_of_node0=0
43
44HUGEPAGESIZE=$(awk '/Hugepagesize/{ print $2 }' /proc/meminfo)
45HUGEPAGESIZE=$(($HUGEPAGESIZE * 1024))
46
47MEMORY_RESULT="$CPUSET_TMP/memory_result"
48
49# simple_getresult
50# $1 - cpuset_memory_test's pid
51# $2 - move cpuset_memory_test's pid to this cpuset
52simple_getresult()
53{
54	sleep 1
55	echo $1 > "$2/tasks"
56	/bin/kill -s SIGUSR1 $1
57	sleep 1
58	/bin/kill -s SIGINT $1
59	wait $1
60	read node < "$MEMORY_RESULT"
61}
62
63test1()
64{
65	cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
66	if [ $? -ne 0 ]; then
67		cpuset_log_error $CPUSET_TMP/stderr
68		tst_resm TFAIL "set general group parameter failed."
69		return 1
70	fi
71
72	./cpuset_memory_test --mmap-anon >"$MEMORY_RESULT" &
73	simple_getresult $! "$CPUSET/0"
74	if [ "$node" != "0" ]; then
75		tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
76		return 1
77	fi
78}
79
80test2()
81{
82	cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
83	if [ $? -ne 0 ]; then
84		cpuset_log_error $CPUSET_TMP/stderr
85		tst_resm TFAIL "set general group parameter failed."
86		return 1
87	fi
88
89	./cpuset_memory_test --mmap-file >"$MEMORY_RESULT" &
90	simple_getresult $! "$CPUSET/0"
91	if [ "$node" != "0" ]; then
92		tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
93		return 1
94	fi
95}
96
97test3()
98{
99	cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
100	if [ $? -ne 0 ]; then
101		cpuset_log_error $CPUSET_TMP/stderr
102		tst_resm TFAIL "set general group parameter failed."
103		return 1
104	fi
105
106	./cpuset_memory_test --shm >"$MEMORY_RESULT" &
107	simple_getresult $! "$CPUSET/0"
108	if [ "$node" != "0" ]; then
109		tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
110		return 1
111	fi
112}
113
114test4()
115{
116	cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
117	if [ $? -ne 0 ]; then
118		cpuset_log_error $CPUSET_TMP/stderr
119		tst_resm TFAIL "set general group parameter failed."
120		return 1
121	fi
122
123	./cpuset_memory_test --mmap-lock1 >"$MEMORY_RESULT" &
124	simple_getresult $! "$CPUSET/0"
125	if [ "$node" != "0" ]; then
126		tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
127		return 1
128	fi
129}
130
131test5()
132{
133	cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
134	if [ $? -ne 0 ]; then
135		cpuset_log_error $CPUSET_TMP/stderr
136		tst_resm TFAIL "set general group parameter failed."
137		return 1
138	fi
139
140	./cpuset_memory_test --mmap-lock2 >"$MEMORY_RESULT" &
141	simple_getresult $! "$CPUSET/0"
142	if [ "$node" != "0" ]; then
143		tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
144		return 1
145	fi
146}
147
148# check whether the system supports hugetlbfs or not
149# return 0 - don't support hugetlbfs
150#        1 - support hugetlbfs
151check_hugetlbfs()
152{
153	local fssupport="grep -w hugetlbfs /proc/filesystems 2>/dev/null | cut -f2"
154
155	if [ "$fssupport" = "hugetlbfs" ]; then
156		return 1
157	else
158		return 0
159	fi
160}
161
162test6()
163{
164	cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
165	if [ $? -ne 0 ]; then
166		cpuset_log_error $CPUSET_TMP/stderr
167		tst_resm TFAIL "set general group parameter failed."
168		return 1
169	fi
170
171	check_hugetlbfs
172	if [ $? -eq 0 ]; then
173		tst_resm TCONF "This system don't support hugetlbfs"
174		return 0
175	fi
176
177	mkdir /hugetlb
178	mount -t hugetlbfs none /hugetlb
179
180	save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
181	echo 2 > /proc/sys/vm/nr_hugepages
182
183	./cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
184	simple_getresult $! "$CPUSET/0"
185
186	umount /hugetlb
187	rmdir /hugetlb
188
189	echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
190	if [ $! -ne 0 ]; then
191		tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
192		return 1
193	fi
194
195	if [ "$node" != "0" ]; then
196		tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
197		return 1
198	fi
199}
200
201test7()
202{
203	cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
204	if [ $? -ne 0 ]; then
205		cpuset_log_error $CPUSET_TMP/stderr
206		tst_resm TFAIL "set general group parameter failed."
207		return 1
208	fi
209
210	check_hugetlbfs
211	if [ $? -eq 0 ]; then
212		tst_resm TCONF "This system don't support hugetlbfs"
213		return 0
214	fi
215
216	mkdir /hugetlb
217	mount -t hugetlbfs none /hugetlb
218
219	save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
220	echo 2 > /proc/sys/vm/nr_hugepages
221
222	./cpuset_memory_test --shm --hugepage -s $HUGEPAGESIZE --key=7 >"$MEMORY_RESULT" &
223	simple_getresult $! "$CPUSET/0"
224
225	umount /hugetlb
226	rmdir /hugetlb
227
228	echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
229	if [ $! -ne 0 ]; then
230		tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
231		return 1
232	fi
233
234	if [ "$node" != "0" ]; then
235		tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
236		return 1
237	fi
238}
239
240test8()
241{
242	cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
243	if [ $? -ne 0 ]; then
244		cpuset_log_error $CPUSET_TMP/stderr
245		tst_resm TFAIL "set general group parameter failed."
246		return 1
247	fi
248
249	./cpuset_memory_test --mmap-anon >"$MEMORY_RESULT" &
250	simple_getresult $! "$CPUSET/0"
251	if [ "$node" != "0" ]; then
252		tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
253		return 1
254	fi
255}
256
257test9()
258{
259	cpuset_set "$CPUSET/0" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
260	if [ $? -ne 0 ]; then
261		cpuset_log_error $CPUSET_TMP/stderr
262		tst_resm TFAIL "set general group parameter failed."
263		return 1
264	fi
265
266	./cpuset_memory_test --mmap-anon >"$MEMORY_RESULT" &
267	simple_getresult $! "$CPUSET/0"
268	if [ "$node" != "1" ]; then
269		tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#1)."
270		return 1
271	fi
272}
273
274# talk2memory_test_for_case_10_11
275# $1 - cpuset_memory_test's pid
276# $2 - move cpuset_memory_test's pid to this cpuset
277# $3 - move cpuset_memory_test's pid to this cpuset(a new cpuset)
278talk2memory_test_for_case_10_11()
279{
280	sleep 1
281	echo $1 > "$2/tasks"
282	/bin/kill -s SIGUSR1 $1
283	sleep 1
284	echo $1 > "$3/tasks"
285	/bin/kill -s SIGUSR1 $1
286	sleep 1
287	/bin/kill -s SIGUSR1 $1
288	sleep 1
289	/bin/kill -s SIGINT $1
290	wait $1
291}
292
293test10()
294{
295	cpuset_set "$CPUSET/1" "$cpus_all" "0" "0" 2> $CPUSET_TMP/stderr
296	if [ $? -ne 0 ]; then
297		cpuset_log_error $CPUSET_TMP/stderr
298		tst_resm TFAIL "set general group1's parameter failed."
299		return 1
300	fi
301
302	cpuset_set "$CPUSET/2" "$cpus_all" "1" "0" 2> $CPUSET_TMP/stderr
303	if [ $? -ne 0 ]; then
304		cpuset_log_error $CPUSET_TMP/stderr
305		tst_resm TFAIL "set general group2's parameter failed."
306		return 1
307	fi
308
309	./cpuset_memory_test --mmap-anon --check >"$MEMORY_RESULT" &
310	talk2memory_test_for_case_10_11 $! "$CPUSET/1" "$CPUSET/2"
311	{
312		read node0
313		read node1
314		read node2
315	} < "$MEMORY_RESULT"
316
317	if [ "$node0" != "0" ]; then
318		tst_resm TFAIL "allocate memory on the Node#$node0(Expect: Node#0)."
319		return 1
320	fi
321	if [ "$node1" != "0" ]; then
322		tst_resm TFAIL "Allocated memory was moved to the Node#$node1(Expect: Node#0)."
323		return 1
324	fi
325	if [ "$node2" != "1" ]; then
326		tst_resm TFAIL "allocate memory on the Node#$node2(Expect: Node#1) after changing group."
327		return 1
328	fi
329}
330
331test11()
332{
333	cpuset_set "$CPUSET/1" "$cpus_all" "0" "0" 2> $CPUSET_TMP/stderr
334	if [ $? -ne 0 ]; then
335		cpuset_log_error $CPUSET_TMP/stderr
336		tst_resm TFAIL "set general group1's parameter failed."
337		return 1
338	fi
339
340	cpuset_set "$CPUSET/2" "$cpus_all" "1" "0" 2> $CPUSET_TMP/stderr
341	if [ $? -ne 0 ]; then
342		cpuset_log_error $CPUSET_TMP/stderr
343		tst_resm TFAIL "set general group2's parameter failed."
344		return 1
345	fi
346
347	echo 1 > "$CPUSET/2/memory_migrate" 2> $CPUSET_TMP/stderr
348	if [ $? -ne 0 ]; then
349		cpuset_log_error $CPUSET_TMP/stderr
350		tst_resm TFAIL "set general group2's memory_migrate failed."
351		return 1
352	fi
353
354	./cpuset_memory_test --mmap-anon --check >"$MEMORY_RESULT" &
355	talk2memory_test_for_case_10_11 $! "$CPUSET/1" "$CPUSET/2"
356	{
357		read node0
358		read node1
359		read node2
360	} < "$MEMORY_RESULT"
361
362	if [ "$node0" != "0" ]; then
363		tst_resm TFAIL "allocate memory on the Node#$node0(Expect: Node#0)."
364		return 1
365	fi
366	if [ "$node1" != "1" ]; then
367		tst_resm TFAIL "Allocated memory was not moved to the Node#1(Result: Node#$node1)."
368		return 1
369	fi
370	if [ "$node2" != "1" ]; then
371		tst_resm TFAIL "allocate memory on the Node#$node2(Expect: Node#1) after changing group."
372		return 1
373	fi
374}
375
376
377# talk2memory_test_for_case_12_13
378# $1 - cpuset_memory_test's pid
379# $2 - the test cpuset
380talk2memory_test_for_case_12_13()
381{
382	sleep 1
383	echo $1 > "$2/tasks"
384	/bin/kill -s SIGUSR1 $1
385
386	echo 0 > "$2/mems" || return 1
387	sleep 1
388	/bin/kill -s SIGUSR1 $1
389	sleep 1
390	/bin/kill -s SIGUSR1 $1
391	sleep 1
392	/bin/kill -s SIGINT $1
393	wait $1
394}
395
396
397test12()
398{
399	cpuset_set "$CPUSET/0" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
400	if [ $? -ne 0 ]; then
401		cpuset_log_error $CPUSET_TMP/stderr
402		tst_resm TFAIL "set general group's parameter failed."
403		return 1
404	fi
405
406	./cpuset_memory_test --mmap-anon >"$MEMORY_RESULT" &
407	talk2memory_test_for_case_12_13 $! "$CPUSET/0"
408
409	{
410		read node0
411		read node1
412	} < "$MEMORY_RESULT"
413
414	if [ "$node0" != "1" ]; then
415		tst_resm TFAIL "allocate memory on the Node#$node0(Expect: Node#1)."
416		return 1
417	fi
418	if [ "$node1" != "0" ]; then
419		tst_resm TFAIL "allocate memory on the Node#$node1(Expect: Node#0) after changing mems."
420		return 1
421	fi
422}
423
424
425test13()
426{
427	cpuset_set "$CPUSET/0" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
428	if [ $? -ne 0 ]; then
429		cpuset_log_error $CPUSET_TMP/stderr
430		tst_resm TFAIL "set general group's parameter failed."
431		return 1
432	fi
433
434	echo 1 > "$CPUSET/0/memory_migrate" 2> $CPUSET_TMP/stderr
435	if [ $? -ne 0 ]; then
436		cpuset_log_error $CPUSET_TMP/stderr
437		tst_resm TFAIL "set general group's memory_migrate failed."
438		return 1
439	fi
440
441
442	./cpuset_memory_test --mmap-anon --check >"$MEMORY_RESULT" &
443	talk2memory_test_for_case_12_13 $! "$CPUSET/0"
444
445	{
446		read node0
447		read node1
448		read node2
449	} < "$MEMORY_RESULT"
450
451	if [ "$node0" != "1" ]; then
452		tst_resm TFAIL "allocate memory on the Node#$node0(Expect: Node#1)."
453		return 1
454	fi
455	if [ "$node1" != "0" ]; then
456		tst_resm TFAIL "Allocated memory was not moved to the Node#0(Result: Node#$node1)."
457		return 1
458	fi
459	if [ "$node2" != "0" ]; then
460		tst_resm TFAIL "allocate memory on the Node#$node2(Expect: Node#0) after changing mems."
461		return 1
462	fi
463}
464
465# get the second thread's tid
466#$1 - pid
467get_the_second()
468{
469	ls /proc/$1/task | (
470		read tid1
471		read tid2
472		if [ "$1" -eq "$tid1" ]
473		then
474			echo $tid2
475		else
476			echo $tid1
477		fi
478	)
479}
480
481test14()
482{
483	cpuset_set "$CPUSET/1" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
484	if [ $? -ne 0 ]; then
485		cpuset_log_error $CPUSET_TMP/stderr
486		tst_resm TFAIL "set general group1's parameter failed."
487		return 1
488	fi
489
490	cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
491	if [ $? -ne 0 ]; then
492		cpuset_log_error $CPUSET_TMP/stderr
493		tst_resm TFAIL "set general group2's parameter failed."
494		return 1
495	fi
496
497	./cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
498	{
499		local testpid=$!
500		sleep 1
501		local testtid=$(get_the_second $testpid)
502
503		echo $testpid > "$CPUSET/1/tasks"
504		/bin/kill -s SIGUSR1 $testpid
505
506		echo $testtid > "$CPUSET/2/tasks"
507		sleep 1
508		/bin/kill -s SIGUSR2 $testpid
509		sleep 1
510		/bin/kill -s SIGINT $testpid
511		wait $testpid
512	}
513
514	{
515		read node0
516		read node1
517	} < "$MEMORY_RESULT"
518
519	if [ "$node0" != "0" ]; then
520		tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#0)."
521		return 1
522	fi
523	if [ "$node1" != "1" ]; then
524		tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1)."
525		return 1
526	fi
527}
528
529test15()
530{
531	cpuset_set "$CPUSET/1" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
532	if [ $? -ne 0 ]; then
533		cpuset_log_error $CPUSET_TMP/stderr
534		tst_resm TFAIL "set general group1's parameter failed."
535		return 1
536	fi
537
538	cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
539	if [ $? -ne 0 ]; then
540		cpuset_log_error $CPUSET_TMP/stderr
541		tst_resm TFAIL "set general group2's parameter failed."
542		return 1
543	fi
544
545	echo 1 > "$CPUSET/2/memory_migrate" 2> $CPUSET_TMP/stderr
546	if [ $? -ne 0 ]; then
547		cpuset_log_error $CPUSET_TMP/stderr
548		tst_resm TFAIL "set general group2's memory_migrate failed."
549		return 1
550	fi
551
552
553	./cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
554	{
555		local testpid=$!
556		sleep 1
557		local testtid=$(get_the_second $testpid)
558
559		echo $testpid > "$CPUSET/1/tasks"
560		/bin/kill -s SIGUSR1 $testpid
561
562		echo $testtid > "$CPUSET/2/tasks"
563		sleep 1
564		/bin/kill -s SIGUSR2 $testpid
565		sleep 1
566		/bin/kill -s SIGINT $testpid
567		wait $testpid
568	}
569
570	{
571		read node0
572		read node1
573	} < "$MEMORY_RESULT"
574
575	if [ "$node0" != "0" ]; then
576		tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#0)."
577		return 1
578	fi
579	if [ "$node1" != "1" ]; then
580		tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1)."
581		return 1
582	fi
583}
584
585test16()
586{
587	cpuset_set "$CPUSET/1" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
588	if [ $? -ne 0 ]; then
589		cpuset_log_error $CPUSET_TMP/stderr
590		tst_resm TFAIL "set general group1's parameter failed."
591		return 1
592	fi
593
594	cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
595	if [ $? -ne 0 ]; then
596		cpuset_log_error $CPUSET_TMP/stderr
597		tst_resm TFAIL "set general group2's parameter failed."
598		return 1
599	fi
600
601	echo 1 > "$CPUSET/2/memory_migrate" 2> $CPUSET_TMP/stderr
602	if [ $? -ne 0 ]; then
603		cpuset_log_error $CPUSET_TMP/stderr
604		tst_resm TFAIL "set general group2's memory_migrate failed."
605		return 1
606	fi
607
608
609	./cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
610	{
611		local testpid=$!
612		sleep 1
613		local testtid=$(get_the_second $testpid)
614
615		echo $testpid > "$CPUSET/1/tasks"
616		/bin/kill -s SIGUSR1 $testpid
617
618		echo $testtid > "$CPUSET/2/tasks"
619		sleep 1
620		echo 1 > "$CPUSET/1/memory_migrate"
621		sleep 1
622		/bin/kill -s SIGUSR2 $testpid
623		sleep 1
624		/bin/kill -s SIGUSR1 $testpid
625		sleep 1
626		/bin/kill -s SIGUSR1 $testpid
627		sleep 1
628		/bin/kill -s SIGINT $testpid
629		wait $testpid
630	}
631
632	{
633		read node0
634		read node1
635		read node2
636	} < "$MEMORY_RESULT"
637
638	if [ "$node0" != "0" ]; then
639		tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#0) first."
640		return 1
641	fi
642	if [ "$node1" != "1" ]; then
643		tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1)."
644		return 1
645	fi
646	if [ "$node2" != "0" ]; then
647		tst_resm TFAIL "Thread1 allocated memory on the Node#$node2(Expect: Node#0) second."
648		return 1
649	fi
650}
651
652test17()
653{
654	cpuset_set "$CPUSET/1" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
655	if [ $? -ne 0 ]; then
656		cpuset_log_error $CPUSET_TMP/stderr
657		tst_resm TFAIL "set general group1's parameter failed."
658		return 1
659	fi
660
661	cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
662	if [ $? -ne 0 ]; then
663		cpuset_log_error $CPUSET_TMP/stderr
664		tst_resm TFAIL "set general group2's parameter failed."
665		return 1
666	fi
667
668	echo 1 > "$CPUSET/2/memory_migrate" 2> $CPUSET_TMP/stderr
669	if [ $? -ne 0 ]; then
670		cpuset_log_error $CPUSET_TMP/stderr
671		tst_resm TFAIL "set general group2's memory_migrate failed."
672		return 1
673	fi
674
675	./cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
676	{
677		local testpid=$!
678		sleep 1
679		local testtid=$(get_the_second $testpid)
680
681		echo $testpid > "$CPUSET/1/tasks"
682		/bin/kill -s SIGUSR1 $testpid
683
684		echo $testtid > "$CPUSET/2/tasks"
685		sleep 1
686		echo 0 > "$CPUSET/1/mems"
687		sleep 1
688		/bin/kill -s SIGUSR2 $testpid
689		sleep 1
690		/bin/kill -s SIGUSR1 $testpid
691		sleep 1
692		/bin/kill -s SIGUSR1 $testpid
693		sleep 1
694		/bin/kill -s SIGUSR2 $testpid
695		sleep 1
696		/bin/kill -s SIGUSR2 $testpid
697		sleep 1
698		/bin/kill -s SIGINT $testpid
699		wait $testpid
700	}
701
702	{
703		read node0
704		read node1
705		read node2
706		read node3
707	} < "$MEMORY_RESULT"
708
709	if [ "$node0" != "1" ]; then
710		tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#1) first."
711		return 1
712	fi
713	if [ "$node1" != "1" ]; then
714		tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1) first."
715		return 1
716	fi
717	if [ "$node2" != "0" ]; then
718		tst_resm TFAIL "Thread1 allocated memory on the Node#$node2(Expect: Node#0) second"
719		return 1
720	fi
721	if [ "$node3" != "1" ]; then
722		tst_resm TFAIL "Thread2 allocated memory on the Node#$node3(Expect: Node#1) second"
723		return 1
724	fi
725}
726
727test18()
728{
729	cpuset_set "$CPUSET/1" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
730	if [ $? -ne 0 ]; then
731		cpuset_log_error $CPUSET_TMP/stderr
732		tst_resm TFAIL "set general group1's parameter failed."
733		return 1
734	fi
735
736	echo 1 > "$CPUSET/1/memory_migrate" 2> $CPUSET_TMP/stderr
737	if [ $? -ne 0 ]; then
738		cpuset_log_error $CPUSET_TMP/stderr
739		tst_resm TFAIL "set general group1's memory_migrate failed."
740		return 1
741	fi
742
743	cpuset_set "$CPUSET/2" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
744	if [ $? -ne 0 ]; then
745		cpuset_log_error $CPUSET_TMP/stderr
746		tst_resm TFAIL "set general group2's parameter failed."
747		return 1
748	fi
749
750	echo 1 > "$CPUSET/2/memory_migrate" 2> $CPUSET_TMP/stderr
751	if [ $? -ne 0 ]; then
752		cpuset_log_error $CPUSET_TMP/stderr
753		tst_resm TFAIL "set general group2's memory_migrate failed."
754		return 1
755	fi
756
757	./cpuset_memory_test --thread --mmap-anon >"$MEMORY_RESULT" &
758	{
759		local testpid=$!
760		sleep 1
761		local testtid=$(get_the_second $testpid)
762
763		echo $testpid > "$CPUSET/1/tasks"
764		/bin/kill -s SIGUSR1 $testpid
765
766		echo $testtid > "$CPUSET/2/tasks"
767		sleep 1
768		echo 0 > "$CPUSET/1/mems"
769		sleep 1
770		/bin/kill -s SIGUSR2 $testpid
771		sleep 1
772		/bin/kill -s SIGUSR1 $testpid
773		sleep 1
774		/bin/kill -s SIGUSR1 $testpid
775		sleep 1
776		/bin/kill -s SIGUSR2 $testpid
777		sleep 1
778		/bin/kill -s SIGUSR2 $testpid
779		sleep 1
780		/bin/kill -s SIGINT $testpid
781		wait $testpid
782	}
783
784	{
785		read node0
786		read node1
787		read node2
788		read node3
789	} < "$MEMORY_RESULT"
790
791	if [ "$node0" != "1" ]; then
792		tst_resm TFAIL "Thread1 allocated memory on the Node#$node0(Expect: Node#1) first."
793		return 1
794	fi
795	if [ "$node1" != "1" ]; then
796		tst_resm TFAIL "Thread2 allocated memory on the Node#$node1(Expect: Node#1) first."
797		return 1
798	fi
799	if [ "$node2" != "0" ]; then
800		tst_resm TFAIL "Thread1 allocated memory on the Node#$node2(Expect: Node#0) second"
801		return 1
802	fi
803	if [ "$node3" != "1" ]; then
804		tst_resm TFAIL "Thread2 allocated memory on the Node#$node3(Expect: Node#1) second"
805		return 1
806	fi
807}
808
809for c in $(seq 1 $TST_TOTAL)
810do
811	setup
812	if [ $? -ne 0 ]; then
813		exit_status=1
814	else
815		test$c
816		if [ $? -ne 0 ]; then
817			exit_status=1
818			cleanup
819		else
820			cleanup
821			if [ $? -ne 0 ]; then
822				exit_status=1
823			else
824				tst_resm TPASS "Cpuset memory alloaction test succeeded."
825			fi
826		fi
827	fi
828	TST_COUNT=$(($TST_COUNT + 1))
829done
830
831exit $exit_status
832
833