@@ -4,19 +4,6 @@ set -eux
4
4
5
5
sudo apt-get update
6
6
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
-
20
7
# bug: http://www.postgresql.org/message-id/[email protected]
21
8
sudo update-alternatives --remove-all postmaster.1.gz
22
9
@@ -26,12 +13,41 @@ sudo service postgresql stop
26
13
echo ' exit 0' | sudo tee /etc/init.d/postgresql
27
14
sudo chmod a+x /etc/init.d/postgresql
28
15
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
31
45
46
+ # exit code
47
+ status=0
32
48
33
49
# perform code analysis if necessary
34
- if [ $CHECK_CODE = " true " ]; then
50
+ if [ $CHECK_TYPE = " static " ]; then
35
51
36
52
if [ " $CC " = " clang" ]; then
37
53
sudo apt-get -y install -qq clang-$LLVM_VER
@@ -72,9 +88,14 @@ $initdb_path -D $CLUSTER_PATH -U $USER -A trust
72
88
ulimit -c unlimited -S
73
89
echo ' /tmp/%e-%s-%p.core' | sudo tee /proc/sys/kernel/core_pattern
74
90
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
78
99
79
100
# check build
80
101
status=$?
@@ -85,22 +106,48 @@ sudo chown $USER /var/run/postgresql/
85
106
86
107
# start cluster 'test'
87
108
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
89
118
90
119
# run regression tests
91
120
PGPORT=55435 PGUSER=$USER PG_CONFIG=$config_path make installcheck USE_PGXS=1 || status=$?
92
121
93
122
# show diff if it exists
94
123
if test -f regression.diffs; then cat regression.diffs; fi
95
124
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
+
96
136
# check core dumps if any
97
137
for corefile in $( find /tmp/ -name ' *.core' 2> /dev/null) ; do
98
138
binary=$( gdb -quiet -core $corefile -batch -ex ' info auxv' | grep AT_EXECFN | perl -pe " s/^.*\" (.*)\"\$ /\$ 1/g" )
99
139
echo dumping $corefile for $binary
100
140
gdb --batch --quiet -ex " thread apply all bt full" -ex " quit" $binary $corefile
101
141
done
102
142
143
+ # stop cluster
144
+ $pg_ctl_path -D $CLUSTER_PATH stop -l postgres.log -w
145
+
103
146
# 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
105
152
106
153
exit $status
0 commit comments