11#! /usr/bin/env bash
22
3+ #
34# Copyright (c) 2018, Postgres Professional
4-
5-
6- # provide a decent default level
7- if [-z ${LEVEL+x} ]; then
8- LEVEL=scan-build
9- fi
5+ #
6+ # supported levels:
7+ # * standard
8+ # * scan-build
9+ # * hardcore
10+ # * nightmare
11+ #
1012
1113set -ux
12-
1314status=0
1415
1516
@@ -31,41 +32,41 @@ if [ "$LEVEL" = "scan-build" ]; then
3132fi
3233
3334# build with cassert + valgrind support
34- if [" $LEVEL " = " hardcore" ]; then
35+ if [" $LEVEL " = " hardcore" ]|| [ " $LEVEL " = " nightmare " ] ; then
3536
3637set -e
3738
38- CUSTOM_PG_PATH=$PWD /pg_bin
39+ CUSTOM_PG_BIN=$PWD /pg_bin
40+ CUSTOM_PG_SRC=$PWD /postgresql
3941
4042# here PG_VERSION is provided by postgres:X-alpine docker image
4143wget -O postgresql.tar.bz2" https://ftp.postgresql.org/pub/source/v$PG_VERSION /postgresql-$PG_VERSION .tar.bz2"
4244echo " $PG_SHA256 *postgresql.tar.bz2" | sha256sum -c -
4345
44- mkdirpostgresql
46+ mkdir$CUSTOM_PG_SRC
4547
4648tar \
4749--extract \
4850--file postgresql.tar.bz2 \
49- --directorypostgresql \
51+ --directory$CUSTOM_PG_SRC \
5052--strip-components 1
5153
52- cd postgresql
54+ cd $CUSTOM_PG_SRC
5355
5456# enable Valgrind support
5557sed -i.bak" s/\/* #define USE_VALGRIND *\//#define USE_VALGRIND/g" src/include/pg_config_manual.h
5658
5759# enable additional options
58- eval ./configure \
59- --with-gnu-ld \
60+ ./configure \
6061--enable-debug \
6162--enable-cassert \
62- --prefix=$CUSTOM_PG_PATH
63+ --prefix=$CUSTOM_PG_BIN
6364
64- # TODO: -j$(nproc)
65- make -s -j1&& make install
65+ make -s -j$( nproc) && make -s install
6666
6767# override default PostgreSQL instance
68- export PATH=$CUSTOM_PG_PATH /bin:$PATH
68+ export PATH=$CUSTOM_PG_BIN /bin:$PATH
69+ export LD_LIBRARY_PATH=$CUSTOM_PG_BIN /lib
6970
7071# show pg_config path (just in case)
7172which pg_config
@@ -82,16 +83,43 @@ make USE_PGXS=1 install
8283# initialize database
8384initdb -D$PGDATA
8485
86+ # set appropriate port
87+ export PGPORT=55435
88+ echo " port =$PGPORT " >> $PGDATA /postgresql.conf
89+
8590# restart cluster 'test'
86- echo " port = 55435" >> $PGDATA /postgresql.conf
87- pg_ctl start -l /tmp/postgres.log -w|| status=$?
91+ if [" $LEVEL " = " nightmare" ]; then
92+ ls$CUSTOM_PG_BIN /bin
93+
94+ valgrind \
95+ --leak-check=no \
96+ --time-stamp=yes \
97+ --trace-children=yes \
98+ --gen-suppressions=all \
99+ --suppressions=$CUSTOM_PG_SRC /src/tools/valgrind.supp \
100+ --log-file=/tmp/valgrind-%p.log \
101+ postgres -l /tmp/postgres.log -w|| status=$?
102+ else
103+ pg_ctl start -l /tmp/postgres.log -w|| status=$?
104+ fi
88105
89106# something's wrong, exit now!
90107if [$status -ne 0 ]; then cat /tmp/postgres.log; exit 1; fi
91108
92109# run regression tests
93110export PG_REGRESS_DIFF_OPTS=" -w -U3" # for alpine's diff (BusyBox)
94- PGPORT=55435 make USE_PGXS=1 installcheck|| status=$?
111+ make USE_PGXS=1 installcheck|| status=$?
112+
113+ # show Valgrind logs if necessary
114+ if [" $LEVEL " = " nightmare" ]; then
115+ for f in $( find /tmp -name valgrind-* .log) ; do
116+ if grep -q' Command: [^ ]*/postgres' $f && grep -q' ERROR SUMMARY: [1-9]' $f ; then
117+ echo " ========= Contents of$f "
118+ cat$f
119+ status=1
120+ fi
121+ done
122+ fi
95123
96124# show diff if it exists
97125if test -f regression.diffs; then cat regression.diffs; fi