From 493aa8df1c4ce008ba499116f8e609d960cbb131 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 17 Apr 2018 16:00:19 +0300 Subject: [PATCH 1/8] implement several levels in run_tests.sh --- .travis.yml | 1 + Dockerfile.tmpl | 9 ++++-- mk_dockerfile.sh | 2 +- run_tests.sh | 73 ++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 78cd07d..3243caf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ notifications: on_failure: always env: + - PG_VERSION=10 LEVEL=hardcore - PG_VERSION=10 - PG_VERSION=9.6 - PG_VERSION=9.5 diff --git a/Dockerfile.tmpl b/Dockerfile.tmpl index 4b47679..a57790a 100644 --- a/Dockerfile.tmpl +++ b/Dockerfile.tmpl @@ -1,7 +1,12 @@ FROM postgres:${PG_VERSION}-alpine # Install dependencies -RUN apk add --no-cache clang-analyzer clang perl make musl-dev gcc curl; +RUN apk add --no-cache \ + curl git \ + make musl-dev gcc bison flex coreutils \ + perl perl-utils perl-ipc-run \ + zlib-dev libedit-dev \ + clang-analyzer valgrind; # Environment ENV LANG=C.UTF-8 PGDATA=/pg/data @@ -23,4 +28,4 @@ ADD . /pg/testdir WORKDIR /pg/testdir USER postgres -ENTRYPOINT /run.sh +ENTRYPOINT LEVEL=${LEVEL} /run.sh diff --git a/mk_dockerfile.sh b/mk_dockerfile.sh index ae1473a..0e0e2fe 100755 --- a/mk_dockerfile.sh +++ b/mk_dockerfile.sh @@ -1,2 +1,2 @@ set -eu -sed -e 's/${PG_VERSION}/'${PG_VERSION}/g Dockerfile.tmpl > Dockerfile +sed -e 's/${PG_VERSION}/'${PG_VERSION}/g -e 's/${LEVEL}/'${LEVEL}/g Dockerfile.tmpl > Dockerfile diff --git a/run_tests.sh b/run_tests.sh index 27a89f8..c866710 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -3,30 +3,85 @@ # Copyright (c) 2018, Postgres Professional -set -ux +# provide a decent default level +if [ -z ${LEVEL+x} ]; then + LEVEL=scan-build +fi +set -ux status=0 + # show pg_config just in case pg_config -# perform static analyzis -scan-build --status-bugs make USE_PGXS=1 || status=$? -# something's wrong, exit now! -if [ $status -ne 0 ]; then exit 1; fi +# perform code checks if asked to +if [ "$LEVEL" = "scan-build" ]; then -# don't forget to "make clean" -make USE_PGXS=1 clean + # perform static analyzis + scan-build --status-bugs make USE_PGXS=1 || status=$? -# initialize database -initdb -D $PGDATA + # something's wrong, exit now! + if [ $status -ne 0 ]; then exit 1; fi + + # don't forget to "make clean" + make USE_PGXS=1 clean +fi + +# build with cassert + valgrind support +if [ "$LEVEL" = "hardcore" ]; then + + set -e + + CUSTOM_PG_PATH=$PWD/pg_bin + + # here PG_VERSION is provided by postgres:X-alpine docker image + wget -O postgresql.tar.bz2 "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" + echo "$PG_SHA256 *postgresql.tar.bz2" | sha256sum -c - + + mkdir postgresql + + tar \ + --extract \ + --file postgresql.tar.bz2 \ + --directory postgresql \ + --strip-components 1 + + cd postgresql + + # enable Valgrind support + sed -i.bak "s/\/* #define USE_VALGRIND *\//#define USE_VALGRIND/g" src/include/pg_config_manual.h + + # enable additional options + eval ./configure \ + --with-gnu-ld \ + --enable-debug \ + --enable-cassert \ + --prefix=$CUSTOM_PG_PATH + + # TODO: -j$(nproc) + make -s -j1 && make install + + # override default PostgreSQL instance + export PATH=$CUSTOM_PG_PATH/bin:$PATH + + # show pg_config path (just in case) + which pg_config + + cd - + + set +e +fi # build and install extension (using PG_CPPFLAGS and SHLIB_LINK for gcov) make USE_PGXS=1 PG_CPPFLAGS="-coverage" SHLIB_LINK="-coverage" make USE_PGXS=1 install +# initialize database +initdb -D $PGDATA + # restart cluster 'test' echo "port = 55435" >> $PGDATA/postgresql.conf pg_ctl start -l /tmp/postgres.log -w || status=$? From 9ba3a4fb2b39fc9363e1b4b5b629f1fefb876ba8 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 18 Apr 2018 13:36:04 +0300 Subject: [PATCH 2/8] add support for valgrind --- mk_dockerfile.sh | 18 +++++++++++-- run_tests.sh | 70 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 65 insertions(+), 23 deletions(-) diff --git a/mk_dockerfile.sh b/mk_dockerfile.sh index 0e0e2fe..f15433c 100755 --- a/mk_dockerfile.sh +++ b/mk_dockerfile.sh @@ -1,2 +1,16 @@ -set -eu -sed -e 's/${PG_VERSION}/'${PG_VERSION}/g -e 's/${LEVEL}/'${LEVEL}/g Dockerfile.tmpl > Dockerfile +if [ -z ${PG_VERSION+x} ]; then + echo PG_VERSION is not set! + exit 1 +fi + +if [ -z ${LEVEL+x} ]; then + LEVEL=scan-build +fi + +echo PG_VERSION=${PG_VERSION} +echo LEVEL=${LEVEL} + +sed \ + -e 's/${PG_VERSION}/'${PG_VERSION}/g \ + -e 's/${LEVEL}/'${LEVEL}/g \ + Dockerfile.tmpl > Dockerfile diff --git a/run_tests.sh b/run_tests.sh index c866710..e6cb4cd 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,15 +1,16 @@ #!/usr/bin/env bash +# # Copyright (c) 2018, Postgres Professional - - -# provide a decent default level -if [ -z ${LEVEL+x} ]; then - LEVEL=scan-build -fi +# +# supported levels: +# * standard +# * scan-build +# * hardcore +# * nightmare +# set -ux - status=0 @@ -31,41 +32,41 @@ if [ "$LEVEL" = "scan-build" ]; then fi # build with cassert + valgrind support -if [ "$LEVEL" = "hardcore" ]; then +if [ "$LEVEL" = "hardcore" ] || [ "$LEVEL" = "nightmare" ]; then set -e - CUSTOM_PG_PATH=$PWD/pg_bin + CUSTOM_PG_BIN=$PWD/pg_bin + CUSTOM_PG_SRC=$PWD/postgresql # here PG_VERSION is provided by postgres:X-alpine docker image wget -O postgresql.tar.bz2 "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" echo "$PG_SHA256 *postgresql.tar.bz2" | sha256sum -c - - mkdir postgresql + mkdir $CUSTOM_PG_SRC tar \ --extract \ --file postgresql.tar.bz2 \ - --directory postgresql \ + --directory $CUSTOM_PG_SRC \ --strip-components 1 - cd postgresql + cd $CUSTOM_PG_SRC # enable Valgrind support sed -i.bak "s/\/* #define USE_VALGRIND *\//#define USE_VALGRIND/g" src/include/pg_config_manual.h # enable additional options - eval ./configure \ - --with-gnu-ld \ + ./configure \ --enable-debug \ --enable-cassert \ - --prefix=$CUSTOM_PG_PATH + --prefix=$CUSTOM_PG_BIN - # TODO: -j$(nproc) - make -s -j1 && make install + make -s -j$(nproc) && make -s install # override default PostgreSQL instance - export PATH=$CUSTOM_PG_PATH/bin:$PATH + export PATH=$CUSTOM_PG_BIN/bin:$PATH + export LD_LIBRARY_PATH=$CUSTOM_PG_BIN/lib # show pg_config path (just in case) which pg_config @@ -82,16 +83,43 @@ make USE_PGXS=1 install # initialize database initdb -D $PGDATA +# set appropriate port +export PGPORT=55435 +echo "port = $PGPORT" >> $PGDATA/postgresql.conf + # restart cluster 'test' -echo "port = 55435" >> $PGDATA/postgresql.conf -pg_ctl start -l /tmp/postgres.log -w || status=$? +if [ "$LEVEL" = "nightmare" ]; then + ls $CUSTOM_PG_BIN/bin + + valgrind \ + --leak-check=no \ + --time-stamp=yes \ + --trace-children=yes \ + --gen-suppressions=all \ + --suppressions=$CUSTOM_PG_SRC/src/tools/valgrind.supp \ + --log-file=/tmp/valgrind-%p.log \ + postgres -l /tmp/postgres.log -w || status=$? +else + pg_ctl start -l /tmp/postgres.log -w || status=$? +fi # something's wrong, exit now! if [ $status -ne 0 ]; then cat /tmp/postgres.log; exit 1; fi # run regression tests export PG_REGRESS_DIFF_OPTS="-w -U3" # for alpine's diff (BusyBox) -PGPORT=55435 make USE_PGXS=1 installcheck || status=$? +make USE_PGXS=1 installcheck || status=$? + +# show Valgrind logs if necessary +if [ "$LEVEL" = "nightmare" ]; then + for f in $(find /tmp -name valgrind-*.log); do + if grep -q 'Command: [^ ]*/postgres' $f && grep -q 'ERROR SUMMARY: [1-9]' $f; then + echo "========= Contents of $f" + cat $f + status=1 + fi + done +fi # show diff if it exists if test -f regression.diffs; then cat regression.diffs; fi From af6e719158fd43ce18a09d568158d377ca540b08 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 18 Apr 2018 14:14:07 +0300 Subject: [PATCH 3/8] remove some deps --- Dockerfile.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.tmpl b/Dockerfile.tmpl index a57790a..479ea7d 100644 --- a/Dockerfile.tmpl +++ b/Dockerfile.tmpl @@ -3,8 +3,8 @@ FROM postgres:${PG_VERSION}-alpine # Install dependencies RUN apk add --no-cache \ curl git \ + perl perl-ipc-run \ make musl-dev gcc bison flex coreutils \ - perl perl-utils perl-ipc-run \ zlib-dev libedit-dev \ clang-analyzer valgrind; From c3124ed12d59afc42219fb89017d9e1a83f41d28 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 18 Apr 2018 14:22:34 +0300 Subject: [PATCH 4/8] refactoring, add missing deps --- Dockerfile.tmpl | 2 +- run_tests.sh | 34 +++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Dockerfile.tmpl b/Dockerfile.tmpl index 479ea7d..48ccebb 100644 --- a/Dockerfile.tmpl +++ b/Dockerfile.tmpl @@ -6,7 +6,7 @@ RUN apk add --no-cache \ perl perl-ipc-run \ make musl-dev gcc bison flex coreutils \ zlib-dev libedit-dev \ - clang-analyzer valgrind; + clang clang-analyzer valgrind; # Environment ENV LANG=C.UTF-8 PGDATA=/pg/data diff --git a/run_tests.sh b/run_tests.sh index e6cb4cd..cbb0b75 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -18,21 +18,9 @@ status=0 pg_config -# perform code checks if asked to -if [ "$LEVEL" = "scan-build" ]; then - - # perform static analyzis - scan-build --status-bugs make USE_PGXS=1 || status=$? - - # something's wrong, exit now! - if [ $status -ne 0 ]; then exit 1; fi - - # don't forget to "make clean" - make USE_PGXS=1 clean -fi - -# build with cassert + valgrind support -if [ "$LEVEL" = "hardcore" ] || [ "$LEVEL" = "nightmare" ]; then +# rebuild PostgreSQL with cassert + valgrind support +if [ "$LEVEL" = "hardcore" ] || \ + [ "$LEVEL" = "nightmare" ]; then set -e @@ -76,6 +64,22 @@ if [ "$LEVEL" = "hardcore" ] || [ "$LEVEL" = "nightmare" ]; then set +e fi +# perform code checks if asked to +if [ "$LEVEL" = "scan-build" ] || \ + [ "$LEVEL" = "hardcore" ] || \ + [ "$LEVEL" = "nightmare" ]; then + + # perform static analyzis + scan-build --status-bugs make USE_PGXS=1 || status=$? + + # something's wrong, exit now! + if [ $status -ne 0 ]; then exit 1; fi + + # don't forget to "make clean" + make USE_PGXS=1 clean +fi + + # build and install extension (using PG_CPPFLAGS and SHLIB_LINK for gcov) make USE_PGXS=1 PG_CPPFLAGS="-coverage" SHLIB_LINK="-coverage" make USE_PGXS=1 install From 45948058d0f29ee4298355901e89110c3f5385e4 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 18 Apr 2018 14:45:12 +0300 Subject: [PATCH 5/8] show build time (hardcore mode) --- run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_tests.sh b/run_tests.sh index cbb0b75..cc04cee 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -50,7 +50,7 @@ if [ "$LEVEL" = "hardcore" ] || \ --enable-cassert \ --prefix=$CUSTOM_PG_BIN - make -s -j$(nproc) && make -s install + time make -s -j$(nproc) && make -s install # override default PostgreSQL instance export PATH=$CUSTOM_PG_BIN/bin:$PATH From 67e897068b864ca7b082786e6d2d8e408c1a6586 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Fri, 20 Apr 2018 13:45:00 +0300 Subject: [PATCH 6/8] replace wget with curl --- Dockerfile.tmpl | 2 +- run_tests.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.tmpl b/Dockerfile.tmpl index 48ccebb..0d13eda 100644 --- a/Dockerfile.tmpl +++ b/Dockerfile.tmpl @@ -2,7 +2,7 @@ FROM postgres:${PG_VERSION}-alpine # Install dependencies RUN apk add --no-cache \ - curl git \ + openssl curl \ perl perl-ipc-run \ make musl-dev gcc bison flex coreutils \ zlib-dev libedit-dev \ diff --git a/run_tests.sh b/run_tests.sh index cbb0b75..d3f55c0 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -28,7 +28,7 @@ if [ "$LEVEL" = "hardcore" ] || \ CUSTOM_PG_SRC=$PWD/postgresql # here PG_VERSION is provided by postgres:X-alpine docker image - wget -O postgresql.tar.bz2 "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" + curl "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" -o postgresql.tar.bz2 echo "$PG_SHA256 *postgresql.tar.bz2" | sha256sum -c - mkdir $CUSTOM_PG_SRC From 25ecc76124dca188cf046830f9d11af565ac77d5 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 23 Apr 2018 18:16:15 +0300 Subject: [PATCH 7/8] run builds under Valgrind --- .travis.yml | 5 +++++ Dockerfile.tmpl | 7 ++++++- run_tests.sh | 18 +++++++++--------- valgrind.supp | 0 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 valgrind.supp diff --git a/.travis.yml b/.travis.yml index 3243caf..6d40aa6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,12 @@ notifications: on_failure: always env: + - PG_VERSION=10 LEVEL=nightmare - PG_VERSION=10 LEVEL=hardcore - PG_VERSION=10 - PG_VERSION=9.6 - PG_VERSION=9.5 + +matrix: + allow_failures: + - env: PG_VERSION=10 LEVEL=nightmare diff --git a/Dockerfile.tmpl b/Dockerfile.tmpl index 0d13eda..1760377 100644 --- a/Dockerfile.tmpl +++ b/Dockerfile.tmpl @@ -6,7 +6,12 @@ RUN apk add --no-cache \ perl perl-ipc-run \ make musl-dev gcc bison flex coreutils \ zlib-dev libedit-dev \ - clang clang-analyzer valgrind; + clang clang-analyzer; + +# Install fresh valgrind +RUN apk add valgrind \ + --update-cache \ + --repository http://dl-3.alpinelinux.org/alpine/edge/main; # Environment ENV LANG=C.UTF-8 PGDATA=/pg/data diff --git a/run_tests.sh b/run_tests.sh index 8132856..4bf8a09 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -14,10 +14,6 @@ set -ux status=0 -# show pg_config just in case -pg_config - - # rebuild PostgreSQL with cassert + valgrind support if [ "$LEVEL" = "hardcore" ] || \ [ "$LEVEL" = "nightmare" ]; then @@ -46,7 +42,7 @@ if [ "$LEVEL" = "hardcore" ] || \ # enable additional options ./configure \ - --enable-debug \ + CFLAGS='-O0 -ggdb3 -fno-omit-frame-pointer' \ --enable-cassert \ --prefix=$CUSTOM_PG_BIN @@ -64,6 +60,9 @@ if [ "$LEVEL" = "hardcore" ] || \ set +e fi +# show pg_config just in case +pg_config + # perform code checks if asked to if [ "$LEVEL" = "scan-build" ] || \ [ "$LEVEL" = "hardcore" ] || \ @@ -81,8 +80,7 @@ fi # build and install extension (using PG_CPPFLAGS and SHLIB_LINK for gcov) -make USE_PGXS=1 PG_CPPFLAGS="-coverage" SHLIB_LINK="-coverage" -make USE_PGXS=1 install +make USE_PGXS=1 PG_CPPFLAGS="-coverage" SHLIB_LINK="-coverage" install # initialize database initdb -D $PGDATA @@ -96,13 +94,16 @@ if [ "$LEVEL" = "nightmare" ]; then ls $CUSTOM_PG_BIN/bin valgrind \ + --tool=memcheck \ --leak-check=no \ --time-stamp=yes \ + --track-origins=yes \ --trace-children=yes \ --gen-suppressions=all \ --suppressions=$CUSTOM_PG_SRC/src/tools/valgrind.supp \ + --suppressions=$PWD/valgrind.supp \ --log-file=/tmp/valgrind-%p.log \ - postgres -l /tmp/postgres.log -w || status=$? + pg_ctl start -l /tmp/postgres.log -w || status=$? else pg_ctl start -l /tmp/postgres.log -w || status=$? fi @@ -132,7 +133,6 @@ if test -f regression.diffs; then cat regression.diffs; fi if [ $status -ne 0 ]; then exit 1; fi # generate *.gcov files -rm -f *serialize.{gcda,gcno} gcov *.c *.h diff --git a/valgrind.supp b/valgrind.supp new file mode 100644 index 0000000..e69de29 From eb1d7f84c06199e81735d979aeb8a0ff89374a8f Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 23 Apr 2018 18:21:22 +0300 Subject: [PATCH 8/8] use ./configure ... --quiet --- run_tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run_tests.sh b/run_tests.sh index 4bf8a09..2574328 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -44,7 +44,8 @@ if [ "$LEVEL" = "hardcore" ] || \ ./configure \ CFLAGS='-O0 -ggdb3 -fno-omit-frame-pointer' \ --enable-cassert \ - --prefix=$CUSTOM_PG_BIN + --prefix=$CUSTOM_PG_BIN \ + --quiet time make -s -j$(nproc) && make -s install