Skip to content

Commit 6b69b4e

Browse files
committed
Add travis tests
1 parent 6ed9e85 commit 6b69b4e

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
os:
2+
- linux
3+
4+
sudo: required
5+
dist: trusty
6+
7+
language: c
8+
9+
services:
10+
- docker
11+
12+
install:
13+
- sed -e 's/${CHECK_CODE}/'${CHECK_CODE}/g -e 's/${PG_VERSION}/'${PG_VERSION}/g Dockerfile.tmpl > Dockerfile
14+
- docker-compose build
15+
16+
script:
17+
- docker-compose run tests
18+
19+
env:
20+
- PG_VERSION=9.6 CHECK_CODE=clang
21+
- PG_VERSION=9.6 CHECK_CODE=cppcheck
22+
- PG_VERSION=9.6 CHECK_CODE=false
23+
- PG_VERSION=10 CHECK_CODE=clang
24+
- PG_VERSION=10 CHECK_CODE=cppcheck
25+
- PG_VERSION=10 CHECK_CODE=false
26+
- PG_VERSION=11 CHECK_CODE=clang
27+
- PG_VERSION=11 CHECK_CODE=cppcheck
28+
- PG_VERSION=11 CHECK_CODE=false

Dockerfile.tmpl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM postgres:${PG_VERSION}-alpine
2+
3+
ENV LANG=C.UTF-8 PGDATA=/pg/data
4+
5+
RUN if [ "${CHECK_CODE}" = "clang" ] ; then \
6+
echo 'http://dl-3.alpinelinux.org/alpine/edge/main' > /etc/apk/repositories; \
7+
apk --no-cache add clang-analyzer make musl-dev gcc; \
8+
fi
9+
10+
RUN if [ "${CHECK_CODE}" = "cppcheck" ] ; then \
11+
apk --no-cache add cppcheck --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/community; \
12+
fi
13+
14+
RUN if [ "${CHECK_CODE}" = "false" ] ; then \
15+
echo 'http://dl-3.alpinelinux.org/alpine/edge/main' > /etc/apk/repositories; \
16+
apk --no-cache add curl python3 gcc make musl-dev;\
17+
fi
18+
19+
RUN mkdir -p /pg/data && \
20+
mkdir /pg/src && \
21+
chown postgres:postgres ${PGDATA} && \
22+
chmod a+rwx /usr/local/lib/postgresql && \
23+
chmod a+rwx /usr/local/share/postgresql/extension
24+
25+
ADD . /pg/src
26+
WORKDIR /pg/src
27+
RUN chmod -R go+rwX /pg/src
28+
USER postgres
29+
ENTRYPOINT PGDATA=${PGDATA} CHECK_CODE=${CHECK_CODE} bash run_tests.sh

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests:
2+
build: .

run_tests.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2018, Postgres Professional
4+
5+
set -eux
6+
7+
echo CHECK_CODE=$CHECK_CODE
8+
9+
status=0
10+
11+
# perform code analysis if necessary
12+
if [ "$CHECK_CODE" = "clang" ]; then
13+
scan-build --status-bugs make USE_PGXS=1 || status=$?
14+
exit $status
15+
16+
elif [ "$CHECK_CODE" = "cppcheck" ]; then
17+
cppcheck \
18+
--template "{file} ({line}): {severity} ({id}): {message}" \
19+
--enable=warning,portability,performance \
20+
--suppress=redundantAssignment \
21+
--suppress=uselessAssignmentPtrArg \
22+
--suppress=literalWithCharPtrCompare \
23+
--suppress=incorrectStringBooleanError \
24+
--std=c89 *.c *.h 2> cppcheck.log
25+
26+
if [ -s cppcheck.log ]; then
27+
cat cppcheck.log
28+
status=1 # error
29+
fi
30+
31+
exit $status
32+
fi
33+
34+
# don't forget to "make clean"
35+
make USE_PGXS=1 clean
36+
37+
# initialize database
38+
initdb
39+
40+
# build extension
41+
make USE_PGXS=1 install
42+
43+
# check build
44+
status=$?
45+
if [ $status -ne 0 ]; then exit $status; fi
46+
47+
# add pg_pathman to shared_preload_libraries and restart cluster 'test'
48+
echo "shared_preload_libraries = 'sr_plan'" >> $PGDATA/postgresql.conf
49+
echo "port = 55435" >> $PGDATA/postgresql.conf
50+
pg_ctl start -l /tmp/postgres.log -w
51+
52+
# check startup
53+
status=$?
54+
if [ $status -ne 0 ]; then cat /tmp/postgres.log; fi
55+
56+
# run regression tests
57+
export PG_REGRESS_DIFF_OPTS="-w -U3" # for alpine's diff (BusyBox)
58+
PGPORT=55435 make USE_PGXS=1 installcheck || status=$?
59+
60+
# show diff if it exists
61+
if test -f regression.diffs; then cat regression.diffs; fi
62+
63+
exit $status

0 commit comments

Comments
 (0)