Skip to content

Commit 08efd62

Browse files
authored
Merge pull request #8 from funbringer/travis_hardcore
New Travis CI -based checks (--enable-cassert + Valgrind)
2 parents e38097a + eb1d7f8 commit 08efd62

File tree

5 files changed

+137
-19
lines changed

5 files changed

+137
-19
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ notifications:
1818
on_failure: always
1919

2020
env:
21+
- PG_VERSION=10 LEVEL=nightmare
22+
- PG_VERSION=10 LEVEL=hardcore
2123
- PG_VERSION=10
2224
- PG_VERSION=9.6
2325
- PG_VERSION=9.5
26+
27+
matrix:
28+
allow_failures:
29+
- env: PG_VERSION=10 LEVEL=nightmare

Dockerfile.tmpl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
FROM postgres:${PG_VERSION}-alpine
22

33
# Install dependencies
4-
RUN apk add --no-cache clang-analyzer clang perl make musl-dev gcc curl;
4+
RUN apk add --no-cache \
5+
openssl curl \
6+
perl perl-ipc-run \
7+
make musl-dev gcc bison flex coreutils \
8+
zlib-dev libedit-dev \
9+
clang clang-analyzer;
10+
11+
# Install fresh valgrind
12+
RUN apk add valgrind \
13+
--update-cache \
14+
--repository http://dl-3.alpinelinux.org/alpine/edge/main;
515

616
# Environment
717
ENV LANG=C.UTF-8 PGDATA=/pg/data
@@ -23,4 +33,4 @@ ADD . /pg/testdir
2333
WORKDIR /pg/testdir
2434

2535
USER postgres
26-
ENTRYPOINT /run.sh
36+
ENTRYPOINT LEVEL=${LEVEL} /run.sh

mk_dockerfile.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
set -eu
2-
sed -e 's/${PG_VERSION}/'${PG_VERSION}/g Dockerfile.tmpl > Dockerfile
1+
if [ -z ${PG_VERSION+x} ]; then
2+
echo PG_VERSION is not set!
3+
exit 1
4+
fi
5+
6+
if [ -z ${LEVEL+x} ]; then
7+
LEVEL=scan-build
8+
fi
9+
10+
echo PG_VERSION=${PG_VERSION}
11+
echo LEVEL=${LEVEL}
12+
13+
sed \
14+
-e 's/${PG_VERSION}/'${PG_VERSION}/g \
15+
-e 's/${LEVEL}/'${LEVEL}/g \
16+
Dockerfile.tmpl > Dockerfile

run_tests.sh

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,131 @@
11
#!/usr/bin/env bash
22

3+
#
34
# Copyright (c) 2018, Postgres Professional
4-
5+
#
6+
# supported levels:
7+
# * standard
8+
# * scan-build
9+
# * hardcore
10+
# * nightmare
11+
#
512

613
set -ux
14+
status=0
715

816

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
1063

1164
# show pg_config just in case
1265
pg_config
1366

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
1671

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=$?
1974

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
2285

2386
# initialize database
2487
initdb -D $PGDATA
2588

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
2992

3093
# 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
33111

34112
# something's wrong, exit now!
35113
if [ $status -ne 0 ]; then cat /tmp/postgres.log; exit 1; fi
36114

37115
# run regression tests
38116
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
40129

41130
# show diff if it exists
42131
if test -f regression.diffs; then cat regression.diffs; fi
@@ -45,7 +134,6 @@ if test -f regression.diffs; then cat regression.diffs; fi
45134
if [ $status -ne 0 ]; then exit 1; fi
46135

47136
# generate *.gcov files
48-
rm -f *serialize.{gcda,gcno}
49137
gcov *.c *.h
50138

51139

valgrind.supp

Whitespace-only changes.

0 commit comments

Comments
 (0)