Skip to content

Commit dfaf02c

Browse files
automate valgrind memory leak detection with travis for linux
1 parent c90f2d6 commit dfaf02c

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ script:
2525
- cd $TRAVIS_BUILD_DIR
2626
- sh build_px.sh "build_$TRAVIS_OS_NAME.sh" "testrunner_$TRAVIS_OS_NAME.sh"
2727
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sh pxleakcheck_linux.sh; fi
28+
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sh valgrind_linux.sh; fi
2829
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then cd $TRAVIS_BUILD_DIR; fi
2930
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then tar -cvzf logs.tgz logs/* ; fi
3031
addons:

examples/pxScene2d/src/pxscene.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,23 @@ export LD_LIBRARY_PATH=$PathR
1616
export NODE_PATH=.
1717

1818
#export RT_LOG_LEVEL=info
19-
19+
20+
if [ $ENABLE_VALGRIND -eq 1 ]
21+
then
22+
if [ -z $VALGRINDLOGS ]
23+
then
24+
VALGRINDLOGS=valgrind_logs
25+
fi
26+
echo "valgrind --tool=memcheck --log-file=$VALGRINDLOGS --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./pxscene $1 $2 $3 $4 $5 $6 $7"
27+
if [ -z $SUPPRESSIONS ]
28+
then
29+
valgrind --tool=memcheck --log-file=$VALGRINDLOGS --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./pxscene $1 $2 $3 $4 $5 $6 $7
30+
else
31+
valgrind --tool=memcheck --suppressions=$SUPPRESSIONS --log-file=$VALGRINDLOGS --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./pxscene $1 $2 $3 $4 $5 $6 $7
32+
fi
33+
else
2034
./pxscene $1 $2 $3 $4 $5 $6 $7
35+
fi
2136
#To run pxscene as background process
2237
#./pxscene $1 $2 $3 $4 $5 $6 $7 < `tty` >> /var/tmp/pxscene.log 2>&1 &
2338

leak.supp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
glutLeaks
3+
Memcheck:Leak
4+
match-leak-kinds:definite
5+
fun:malloc
6+
...
7+
fun:glXMakeContextCurrent
8+
fun:fgOpenWindow
9+
...
10+
}

valgrind_linux.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
export VALGRINDLOGS=$TRAVIS_BUILD_DIR/logs/valgrind_logs
3+
export ENABLE_VALGRIND=1
4+
export PX_DUMP_MEMUSAGE=1
5+
export SUPPRESSIONS=$TRAVIS_BUILD_DIR/leak.supp
6+
VALGRINDPXCORELOGS=$TRAVIS_BUILD_DIR/logs/valgrind_pxcore_logs
7+
8+
#run valgrind and monitor for completion
9+
cd $TRAVIS_BUILD_DIR/examples/pxScene2d/src
10+
./pxscene.sh testRunner_memcheck.js > $VALGRINDPXCORELOGS &
11+
grep "RUN COMPLETED" $VALGRINDPXCORELOGS
12+
retVal=$?
13+
count=0
14+
while [ "$retVal" -ne 0 ] && [ "$count" -lt 600 ]; do
15+
sleep 30;
16+
grep "RUN COMPLETED" $VALGRINDPXCORELOGS
17+
retVal=$?
18+
count=$((count+30))
19+
echo "Valgrind execution going on for $count seconds";
20+
done
21+
22+
#kill pxscene either after js terminates or no response for 5 minutes
23+
echo "`ps -ef | grep valgrind |grep -v grep|grep pxscene|grep -v pxscene.sh|awk '{print $2}'`"
24+
kill -15 `ps -ef | grep valgrind |grep -v grep|grep pxscene|grep -v pxscene.sh|awk '{print $2}'`
25+
sleep 5s;
26+
pkill -9 -f pxscene.sh
27+
28+
#check whether valgrind got completed
29+
grep "definitely lost" $VALGRINDLOGS
30+
retVal=$?
31+
if [ "$retVal" -ne 0 ]
32+
then
33+
echo "Valgrind execution got stuck and not terminated in 5 minutes";
34+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]
35+
then
36+
cat $VALGRINDLOGS
37+
fi
38+
exit 1;
39+
fi
40+
41+
#check for memory leak
42+
grep "definitely lost: 0 bytes in 0 blocks" $VALGRINDLOGS
43+
retVal=$?
44+
if [ "$retVal" -eq 0 ]
45+
then
46+
exit 0;
47+
else
48+
echo "!!!!!!!!!!!!! Memory leak present !!!!!!!!!!!!!!!!!!!";
49+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]
50+
then
51+
cat $VALGRINDLOGS
52+
fi
53+
exit 1;
54+
fi

0 commit comments

Comments
 (0)