2014-11-03 58 views
0

特林讓腳本什麼檢查是有一個內存泄漏或試圖訪問壞內存Cheking內存的valgrind與bash腳本

被特林這個腳本 但沒有運氣,當PROG與警告,編譯後的Cuz Valgrind的給我「BAD」的地位,這就是即使不存在泄漏MEM

#!/bin/bash 
#some varibles for the future 
output=${1} 
progname=${2} 
input=${3} 
trash="/dev/null" 

# execute the prog and putting output to out file 
valgrind --error-exitcode=1 ./${progname} < ${input} >${output} 2>&1 

# grab exit status of valgrind (0 if all good ,1 if not) 
ret=$? 

# write appropriate message as per return status value 
((ret == 0)) && echo "Memory V" || echo "Memory X" 

# return the exit status of testMemory 
exit $ret 

我想,也許一些像這樣的代碼

# cheking for patters that indicate err 
#if [[ grep "ERROR SUMMARY: 0 errors" "$output" ]] # >"$trash" 2>&1 
#then 
# ret=0 
#else 
# ret=1 
#fi 


any ideas? 
+0

「因爲當了前衛與警告編譯它給了我‘OK’狀態」 - 笏?您甚至不會在腳本中編譯... – 2014-11-03 09:37:24

+0

在所示的第二個腳本中,爲什麼要搜索「$ input」文件中的錯誤模式?我想你應該在「$ output」文件中這樣做。 – Jdamian 2014-11-03 09:46:13

+0

是的,你是對的,但仍然沒有工作.. – JohnnyF 2014-11-03 10:05:12

回答

0

我只是做這種方式 我希望它會檢查所有ERRS

#!/bin/bash 

#some varibles for the future 
output=${1} 
progname=${2} 
input=${3} 
trash="/dev/null" 

# execute the prog and putting output to out file 
valgrind ./${progname} < ${input} >${output} 2>&1 
# cheking for patters that indicate err 
grep -q "ERROR SUMMARY: 0 errors" "$output" 

# grab exit status of grep (0 if all good ,1 if not) 
ret=$? 

# write appropriate message as per return status value 
((ret == 0)) && echo "Memory V" || echo "Memory X" 

# return the exit status of testMem 
exit $ret