Skip to content

Commit 1fc03c8

Browse files
MartinDelilleetherealjoy
authored andcommitted
cpp-qt5-client: add valgrind memory test (#3663)
1 parent d64ec14 commit 1fc03c8

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ before_install:
9494
# - Rely on `kerl` for [pre-compiled versions available](https://docs.travis-ci.com/user/languages/erlang#Choosing-OTP-releases-to-test-against). Rely on installation path chosen by [`travis-erlang-builder`](https://github.com/travis-ci/travis-erlang-builder/blob/e6d016b1a91ca7ecac5a5a46395bde917ea13d36/bin/compile#L18).
9595
# - . ~/otp/18.2.1/activate && erl -version
9696
#- curl -f -L -o ./rebar3 https://s3.amazonaws.com/rebar3/rebar3 && chmod +x ./rebar3 && ./rebar3 version && export PATH="${TRAVIS_BUILD_DIR}:$PATH"
97+
# install valgrind for C++ memory test
98+
- sudo apt-get install valgrind
9799
# install Qt 5.10
98100
- sudo add-apt-repository --yes ppa:beineri/opt-qt-5.10.1-trusty
99101
- sudo apt-get update -qq

samples/client/petstore/cpp-qt5/PetStore/PetStore.pro

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ SOURCES += main.cpp \
2626
HEADERS += PetApiTests.h \
2727
StoreApiTests.h \
2828
UserApiTests.h
29+
30+
# Disable optimisation for better valgrind report
31+
QMAKE_CXXFLAGS_DEBUG += -O0

samples/client/petstore/cpp-qt5/build-and-test.bash

+34-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,41 @@
22

33
set -e
44

5-
mkdir build
5+
mkdir -p build
66
cd build
77

8-
qmake ../PetStore/PetStore.pro
8+
qmake ../PetStore/PetStore.pro CONFIG+=debug
9+
910
make
1011

11-
./PetStore
12+
valgrind --leak-check=full ./PetStore |& tee result.log || exit 1
13+
14+
echo "Make sure the tests are launched:"
15+
testCount=$(cat result.log | grep 'Finished testing of' | wc -l)
16+
if [ $testCount == 3 ]
17+
then
18+
echo "Ok"
19+
else
20+
echo "The tests were not run!!!"
21+
exit 1
22+
fi
23+
24+
echo "Make sure the tests passed:"
25+
successCount=$(cat result.log | grep '0 failed' | wc -l)
26+
if [ $successCount == 3 ]
27+
then
28+
echo "Ok"
29+
else
30+
echo "The tests failed!!!"
31+
exit 1
32+
fi
33+
34+
echo "Check if no memory leaks occured:"
35+
leakCount=$(cat result.log | grep 'lost: 0 bytes in 0 blocks' | wc -l)
36+
if [ $leakCount == 3 ]
37+
then
38+
echo "Ok"
39+
else
40+
echo "There was memory leaks!!!"
41+
exit 1
42+
fi

0 commit comments

Comments
 (0)