1
1
#! /usr/bin/env bash
2
2
3
+ #
3
4
# Copyright (c) 2018, Postgres Professional
4
-
5
+ #
6
+ # supported levels:
7
+ # * standard
8
+ # * scan-build
9
+ # * hardcore
10
+ # * nightmare
11
+ #
5
12
6
13
set -ux
14
+ status=0
7
15
8
16
9
- status=0
17
+ # rebuild PostgreSQL with cassert + valgrind support
18
+ if [ " $LEVEL " = " hardcore" ] || \
19
+ [ " $LEVEL " = " nightmare" ]; then
20
+
21
+ set -e
22
+
23
+ CUSTOM_PG_BIN=$PWD /pg_bin
24
+ CUSTOM_PG_SRC=$PWD /postgresql
25
+
26
+ # here PG_VERSION is provided by postgres:X-alpine docker image
27
+ curl " https://ftp.postgresql.org/pub/source/v$PG_VERSION /postgresql-$PG_VERSION .tar.bz2" -o postgresql.tar.bz2
28
+ echo " $PG_SHA256 *postgresql.tar.bz2" | sha256sum -c -
29
+
30
+ mkdir $CUSTOM_PG_SRC
31
+
32
+ tar \
33
+ --extract \
34
+ --file postgresql.tar.bz2 \
35
+ --directory $CUSTOM_PG_SRC \
36
+ --strip-components 1
37
+
38
+ cd $CUSTOM_PG_SRC
39
+
40
+ # enable Valgrind support
41
+ sed -i.bak " s/\/* #define USE_VALGRIND *\//#define USE_VALGRIND/g" src/include/pg_config_manual.h
42
+
43
+ # enable additional options
44
+ ./configure \
45
+ CFLAGS=' -O0 -ggdb3 -fno-omit-frame-pointer' \
46
+ --enable-cassert \
47
+ --prefix=$CUSTOM_PG_BIN \
48
+ --quiet
49
+
50
+ time make -s -j$( nproc) && make -s install
51
+
52
+ # override default PostgreSQL instance
53
+ export PATH=$CUSTOM_PG_BIN /bin:$PATH
54
+ export LD_LIBRARY_PATH=$CUSTOM_PG_BIN /lib
55
+
56
+ # show pg_config path (just in case)
57
+ which pg_config
58
+
59
+ cd -
60
+
61
+ set +e
62
+ fi
10
63
11
64
# show pg_config just in case
12
65
pg_config
13
66
14
- # perform static analyzis
15
- scan-build --status-bugs make USE_PGXS=1 || status=$?
67
+ # perform code checks if asked to
68
+ if [ " $LEVEL " = " scan-build" ] || \
69
+ [ " $LEVEL " = " hardcore" ] || \
70
+ [ " $LEVEL " = " nightmare" ]; then
16
71
17
- # something's wrong, exit now!
18
- if [ $ status -ne 0 ] ; then exit 1 ; fi
72
+ # perform static analyzis
73
+ scan-build -- status-bugs make USE_PGXS=1 || status= $?
19
74
20
- # don't forget to "make clean"
21
- make USE_PGXS=1 clean
75
+ # something's wrong, exit now!
76
+ if [ $status -ne 0 ]; then exit 1; fi
77
+
78
+ # don't forget to "make clean"
79
+ make USE_PGXS=1 clean
80
+ fi
81
+
82
+
83
+ # build and install extension (using PG_CPPFLAGS and SHLIB_LINK for gcov)
84
+ make USE_PGXS=1 PG_CPPFLAGS=" -coverage" SHLIB_LINK=" -coverage" install
22
85
23
86
# initialize database
24
87
initdb -D $PGDATA
25
88
26
- # build and install extension (using PG_CPPFLAGS and SHLIB_LINK for gcov)
27
- make USE_PGXS=1 PG_CPPFLAGS= " -coverage " SHLIB_LINK= " -coverage "
28
- make USE_PGXS=1 install
89
+ # set appropriate port
90
+ export PGPORT=55435
91
+ echo " port = $PGPORT " >> $PGDATA /postgresql.conf
29
92
30
93
# restart cluster 'test'
31
- echo " port = 55435" >> $PGDATA /postgresql.conf
32
- pg_ctl start -l /tmp/postgres.log -w || status=$?
94
+ if [ " $LEVEL " = " nightmare" ]; then
95
+ ls $CUSTOM_PG_BIN /bin
96
+
97
+ valgrind \
98
+ --tool=memcheck \
99
+ --leak-check=no \
100
+ --time-stamp=yes \
101
+ --track-origins=yes \
102
+ --trace-children=yes \
103
+ --gen-suppressions=all \
104
+ --suppressions=$CUSTOM_PG_SRC /src/tools/valgrind.supp \
105
+ --suppressions=$PWD /valgrind.supp \
106
+ --log-file=/tmp/valgrind-%p.log \
107
+ pg_ctl start -l /tmp/postgres.log -w || status=$?
108
+ else
109
+ pg_ctl start -l /tmp/postgres.log -w || status=$?
110
+ fi
33
111
34
112
# something's wrong, exit now!
35
113
if [ $status -ne 0 ]; then cat /tmp/postgres.log; exit 1; fi
36
114
37
115
# run regression tests
38
116
export PG_REGRESS_DIFF_OPTS=" -w -U3" # for alpine's diff (BusyBox)
39
- PGPORT=55435 make USE_PGXS=1 installcheck || status=$?
117
+ make USE_PGXS=1 installcheck || status=$?
118
+
119
+ # show Valgrind logs if necessary
120
+ if [ " $LEVEL " = " nightmare" ]; then
121
+ for f in $( find /tmp -name valgrind-* .log) ; do
122
+ if grep -q ' Command: [^ ]*/postgres' $f && grep -q ' ERROR SUMMARY: [1-9]' $f ; then
123
+ echo " ========= Contents of $f "
124
+ cat $f
125
+ status=1
126
+ fi
127
+ done
128
+ fi
40
129
41
130
# show diff if it exists
42
131
if test -f regression.diffs; then cat regression.diffs; fi
@@ -45,7 +134,6 @@ if test -f regression.diffs; then cat regression.diffs; fi
45
134
if [ $status -ne 0 ]; then exit 1; fi
46
135
47
136
# generate *.gcov files
48
- rm -f * serialize.{gcda,gcno}
49
137
gcov * .c * .h
50
138
51
139
0 commit comments