Skip to contentSkip to conversation

memcg_function:fix the wrong of test_proc_kill

PATCH In review Peng Haitao 2 participants 5 messages Dec 16, 2011 – Jan 5, 2012 3 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memcg_function:fix the wrong of test_proc_kill

test_proc_kill() tests process will be killed due to exceed memory limit, but when memcg_process exit due to mmap/munmap fails, the case still pass.

---
 .../memcg/functional/memcg_function_test.sh        |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +11 -1
index 1f07cb5..6cfe9a5 100755
@@ -175,13 +175,23 @@ test_failcnt()
 test_proc_kill()
 {
 	echo $1 > memory.limit_in_bytes
-	$TEST_PATH/memcg_process $2 -s $3 &
+	($TEST_PATH/memcg_process $2 -s $3 2>/tmp/errlog) &
 	pid=$!
 	sleep 1
 	echo $pid > tasks
 
 	/bin/kill -s SIGUSR1 $pid 2> /dev/null
 	sleep 1
+
+	if [ -s /tmp/errlog ]; then
+		err_msg=`cat /tmp/errlog`
+		rm -f /tmp/errlog
+		result $FAIL "$err_msg"
+		return
+	fi
+
+	rm -f /tmp/errlog
+
 	ps -p $pid > /dev/null 2> /dev/null
 	if [ $? -ne 0 ]; then
 		result $PASS "process $pid is killed"
Signature · 17 lines
1.7.1

-- 
Best Regards,
Peng Haitao


------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!

Quoted 24 lines

test_proc_kill() tests process will be killed due to exceed memory limit, but when memcg_process exit due to mmap/munmap fails, the case still pass.

---
 .../memcg/functional/memcg_function_test.sh        |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +1 -1
index 1f07cb5..6cfe9a5 100755
@@ -175,13 +175,23 @@ test_failcnt()
 test_proc_kill()
 {
 	echo $1 > memory.limit_in_bytes
-	$TEST_PATH/memcg_process $2 -s $3 &
+	($TEST_PATH/memcg_process $2 -s $3 2>/tmp/errlog) &
 	pid=$!
 	sleep 1
 	echo $pid > tasks
 
 	/bin/kill -s SIGUSR1 $pid 2> /dev/null
 	sleep 1

testcases/kernel/controllers/memcg/functional/memcg_function_test.sh test_failcnt() · line 194

Quoted 10 lines
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +10 -0
+
+	if [ -s /tmp/errlog ]; then
+		err_msg=`cat /tmp/errlog`
+		rm -f /tmp/errlog
+		result $FAIL "$err_msg"
+		return
+	fi
+
+	rm -f /tmp/errlog
+

Looking into the memcg_process.c it returns return value 1 on failure, catching it correctly is better option here.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 23 lines
Quoted 6 lines
Quoted 6 lines
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +1 -1
-	$TEST_PATH/memcg_process $2 -s $3 &
+	($TEST_PATH/memcg_process $2 -s $3 2>/tmp/errlog) &
 	pid=$!
 	sleep 1
 	echo $pid > tasks
Quoted 16 lines

testcases/kernel/controllers/memcg/functional/memcg_function_test.sh test_failcnt() · line 194

Quoted 12 lines
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +10 -0
 	/bin/kill -s SIGUSR1 $pid 2> /dev/null
 	sleep 1
+
+	if [ -s /tmp/errlog ]; then
+		err_msg=`cat /tmp/errlog`
+		rm -f /tmp/errlog
+		result $FAIL "$err_msg"
+		return
+	fi
+
+	rm -f /tmp/errlog
+

Looking into the memcg_process.c it returns return value 1 on failure, catching it correctly is better option here.

Quoted 5 lines

I also think catching memcg_process's return value is better option, but I think this way is simple.

Can you tell me a simple way to catch return value of background process? Thanks.

See manual pages for jobs and wait.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Hi!

Quoted 11 lines

Cyril Hrubis said the following on 2011-12-28 19:54:

Quoted 5 lines
Quoted 2 lines

Can you tell me a simple way to catch return value of background process? Thanks.

See manual pages for jobs and wait.

Thanks for your suggest.
I know wait, but I think wait is not better than catching error message.

If you think wait is better, the following patch use wait.

Yes, I think this way is better than looking for error logs.

Also note that running the sleep 2; kill ... in background is not necessary as shell is required to save return status from background command if it's pid was saved by $!.

Generally sequence of

command&
pid=$!
kill $pid
wait $pid

Should work as expected.

Quoted 9 lines
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +4 -2
 	sleep 1
 	echo $pid > tasks
 
-	/bin/kill -s SIGUSR1 $pid 2> /dev/null
-	sleep 1
+	{
+		sleep 2
+		/bin/kill -s SIGUSR1 $pid 2> /dev/null
+	}&

testcases/kernel/controllers/memcg/functional/memcg_function_test.sh test_failcnt() · line 197

Quoted 10 lines
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +7 -0
+
+	wait $pid
+	if [ $? -eq 1 ]; then
+		result $FAIL "process $pid is killed by error"
+		return
+	fi
+
 	ps -p $pid > /dev/null 2> /dev/null
 	if [ $? -ne 0 ]; then
 		result $PASS "process $pid is killed"

Hmm I see the problem here, if the test wouldn't exit by the getting the SIGUSR1 the wait will run forever. So the fail based solution may actually be better here, alghough I still think it's a little fragile.

And I recall saying that earlier, the way the memcg_process is controlled by a signal is fundamentally flaved. The correct way for this would be creating a unix socket (or use whatever interface to interprocess communication). Then you can comunicate with the memcg_process running in background and gets it's status that way.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Hi!

Quoted 11 lines
Quoted 11 lines

Also note that running the sleep 2; kill ... in background is not necessary as shell is required to save return status from background command if it's pid was saved by $!.

Generally sequence of

command&
pid=$!
kill $pid
wait $pid

Quoted 8 lines
Quoted 2 lines

Should work as expected.

Thanks for you comment.
I think the following way is better.

test_proc_kill() tests process will be killed due to exceed memory limit, but when memcg_process exit due to mmap/munmap fails, the case still pass.

This one seems right to me as well, commited.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list