Skip to content

Commit 60c696e

Browse files
author
Alexander Korotkov
committed
Run travis-ci with valgrind.
1 parent 2b5d437 commit 60c696e

File tree

2 files changed

+77
-32
lines changed

2 files changed

+77
-32
lines changed

Diff for: .travis.yml

+9-11
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ env:
2020
global:
2121
- LLVM_VER=4.0
2222
matrix:
23-
- PG_VER=10 CHECK_CODE=true
24-
- PG_VER=10 CHECK_CODE=false
25-
- PG_VER=9.6 CHECK_CODE=true
26-
- PG_VER=9.6 CHECK_CODE=false
27-
- PG_VER=9.5 CHECK_CODE=true
28-
- PG_VER=9.5 CHECK_CODE=false
29-
- PG_VER=9.4 CHECK_CODE=true
30-
- PG_VER=9.4 CHECK_CODE=false
23+
- PG_VER=10 CHECK_TYPE=normal
24+
- PG_VER=10 CHECK_TYPE=static
25+
- PG_VER=10 CHECK_TYPE=valgrind
26+
- PG_VER=9.6 CHECK_TYPE=normal
27+
- PG_VER=9.6 CHECK_TYPE=static
28+
- PG_VER=9.5 CHECK_TYPE=normal
29+
- PG_VER=9.5 CHECK_TYPE=static
30+
- PG_VER=9.4 CHECK_TYPE=normal
31+
- PG_VER=9.4 CHECK_TYPE=static
3132

3233
script: bash ./travis/pg-travis-test.sh
33-
34-
after_success:
35-
- bash <(curl -s https://codecov.io/bash)

Diff for: travis/pg-travis-test.sh

+68-21
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@ set -eux
44

55
sudo apt-get update
66

7-
8-
# required packages
9-
apt_packages="postgresql-$PG_VER postgresql-server-dev-$PG_VER postgresql-common build-essential flex bison"
10-
11-
# exit code
12-
status=0
13-
14-
# pg_config path
15-
pg_ctl_path=/usr/lib/postgresql/$PG_VER/bin/pg_ctl
16-
initdb_path=/usr/lib/postgresql/$PG_VER/bin/initdb
17-
config_path=/usr/lib/postgresql/$PG_VER/bin/pg_config
18-
19-
207
# bug: http://www.postgresql.org/message-id/[email protected]
218
sudo update-alternatives --remove-all postmaster.1.gz
229

@@ -26,12 +13,41 @@ sudo service postgresql stop
2613
echo 'exit 0' | sudo tee /etc/init.d/postgresql
2714
sudo chmod a+x /etc/init.d/postgresql
2815

29-
# install required packages
30-
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages
16+
# install PostgreSQL
17+
if [ $CHECK_TYPE = "valgrind" ]; then
18+
# install required packages
19+
apt_packages="build-essential libgd-dev valgrind lcov"
20+
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages
21+
# grab sources from github
22+
tag=`curl -s 'https://api.github.com/repos/postgres/postgres/git/refs/tags' | jq -r '.[] | .ref' | sed 's/^refs\/tags\///' | grep "REL_*${PG_VER/./_}_" | tail -n 1`
23+
prefix="$HOME/pgsql-$tag"
24+
curl "https://codeload.github.com/postgres/postgres/tar.gz/$tag" -o ~/$tag.tar.gz
25+
# build them with valgrind support
26+
pushd ~
27+
tar -xzf "$tag.tar.gz"
28+
cd "postgres-$tag"
29+
./configure --enable-debug --enable-cassert --enable-coverage --prefix=$prefix
30+
sed -i.bak "s/\/* #define USE_VALGRIND *\//#define USE_VALGRIND/g" src/include/pg_config_manual.h
31+
make -sj4
32+
make -sj4 install
33+
popd
34+
export PATH="$prefix/bin:$PATH"
35+
else
36+
apt_packages="postgresql-$PG_VER postgresql-server-dev-$PG_VER postgresql-common build-essential libgd-dev"
37+
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages
38+
prefix=/usr/lib/postgresql/$PG_VER
39+
fi
40+
41+
# config path
42+
pg_ctl_path=$prefix/bin/pg_ctl
43+
initdb_path=$prefix/bin/initdb
44+
config_path=$prefix/bin/pg_config
3145

46+
# exit code
47+
status=0
3248

3349
# perform code analysis if necessary
34-
if [ $CHECK_CODE = "true" ]; then
50+
if [ $CHECK_TYPE = "static" ]; then
3551

3652
if [ "$CC" = "clang" ]; then
3753
sudo apt-get -y install -qq clang-$LLVM_VER
@@ -72,9 +88,14 @@ $initdb_path -D $CLUSTER_PATH -U $USER -A trust
7288
ulimit -c unlimited -S
7389
echo '/tmp/%e-%s-%p.core' | sudo tee /proc/sys/kernel/core_pattern
7490

75-
# build jsquery (using CFLAGS_SL for gcov)
76-
make USE_PGXS=1 PG_CONFIG=$config_path CFLAGS_SL="$($config_path --cflags_sl) -coverage"
77-
sudo make install USE_PGXS=1 PG_CONFIG=$config_path
91+
# build extension (using CFLAGS_SL for gcov)
92+
if [ $CHECK_TYPE == "valgrind" ] && [ $CC = "clang" ]; then
93+
make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path
94+
make install USE_PGXS=1 PG_CONFIG=$config_path
95+
else
96+
make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path CFLAGS_SL="$($config_path --cflags_sl) -coverage"
97+
sudo make install USE_PGXS=1 PG_CONFIG=$config_path
98+
fi
7899

79100
# check build
80101
status=$?
@@ -85,22 +106,48 @@ sudo chown $USER /var/run/postgresql/
85106

86107
# start cluster 'test'
87108
echo "port = 55435" >> $CLUSTER_PATH/postgresql.conf
88-
$pg_ctl_path -D $CLUSTER_PATH start -l postgres.log -w
109+
if [ $CHECK_TYPE = "valgrind" ]; then
110+
PGCTLTIMEOUT=600 \
111+
valgrind --leak-check=no --gen-suppressions=all \
112+
--suppressions=$HOME/postgres-$tag/src/tools/valgrind.supp --time-stamp=yes \
113+
--log-file=/tmp/pid-%p.log --trace-children=yes \
114+
$pg_ctl_path -D $CLUSTER_PATH start -l postgres.log -w
115+
else
116+
$pg_ctl_path -D $CLUSTER_PATH start -l postgres.log -w
117+
fi
89118

90119
# run regression tests
91120
PGPORT=55435 PGUSER=$USER PG_CONFIG=$config_path make installcheck USE_PGXS=1 || status=$?
92121

93122
# show diff if it exists
94123
if test -f regression.diffs; then cat regression.diffs; fi
95124

125+
# show valgrind logs if needed
126+
if [ $CHECK_TYPE = "valgrind" ]; then
127+
for f in ` find /tmp -name pid-*.log ` ; do
128+
if grep -q 'Command: [^ ]*/postgres' $f && grep -q 'ERROR SUMMARY: [1-9]' $f; then
129+
echo "========= Contents of $f"
130+
cat $f
131+
status=1
132+
fi
133+
done
134+
fi
135+
96136
# check core dumps if any
97137
for corefile in $(find /tmp/ -name '*.core' 2>/dev/null) ; do
98138
binary=$(gdb -quiet -core $corefile -batch -ex 'info auxv' | grep AT_EXECFN | perl -pe "s/^.*\"(.*)\"\$/\$1/g")
99139
echo dumping $corefile for $binary
100140
gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" $binary $corefile
101141
done
102142

143+
# stop cluster
144+
$pg_ctl_path -D $CLUSTER_PATH stop -l postgres.log -w
145+
103146
#generate *.gcov files
104-
gcov *.c *.h
147+
if [ $CHECK_TYPE == "valgrind" ] && [ $CC = "clang" ]; then
148+
bash <(curl -s https://codecov.io/bash) -x "llvm-cov gcov"
149+
else
150+
bash <(curl -s https://codecov.io/bash)
151+
fi
105152

106153
exit $status

0 commit comments

Comments
 (0)