Skip to content

Commit 0571525

Browse files
committed
Fix tests
1 parent 4d544c8 commit 0571525

15 files changed

+2354
-301
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ regression.out
1212
pg_pathman--*.sql
1313
tags
1414
cscope*
15+
Dockerfile

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@ services:
1010
- docker
1111

1212
install:
13-
- sed -e 's/${CC}/'${CC}/g -e 's/${PG_VERSION}/'${PG_VERSION}/g Dockerfile.tmpl > Dockerfile
13+
- sed -e 's/${CHECK_CODE}/'${CHECK_CODE}/g -e 's/${CC}/'${CC}/g -e 's/${PG_VERSION}/'${PG_VERSION}/g Dockerfile.tmpl > Dockerfile
1414
- docker-compose build
1515

1616
script:
1717
- docker-compose run tests
1818

1919
env:
2020
- PG_VERSION=10 CHECK_CODE=true CC=clang
21-
- PG_VERSION=10 CHECK_CODE=false CC=clang
2221
- PG_VERSION=9.6 CHECK_CODE=true CC=clang
23-
- PG_VERSION=9.6 CHECK_CODE=false CC=clang
2422
- PG_VERSION=9.5 CHECK_CODE=true CC=clang
25-
- PG_VERSION=9.5 CHECK_CODE=false CC=clang
2623
- PG_VERSION=10 CHECK_CODE=true CC=gcc
2724
- PG_VERSION=10 CHECK_CODE=false CC=gcc
2825
- PG_VERSION=9.6 CHECK_CODE=true CC=gcc

Dockerfile.tmpl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
FROM postgres:${PG_VERSION}-alpine
22

3-
ENV LANG=C.UTF-8
4-
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/main' > /etc/apk/repositories && \
5-
echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/community' >> /etc/apk/repositories && \
6-
apk --no-cache add cmocka cppcheck cmake python3 gcc make ${CC}
7-
RUN apk add --no-cache musl-dev cmocka-dev
8-
RUN pip3 install testgres
3+
ENV LANG=C.UTF-8 PGDATA=/pg/data
4+
RUN apk --no-cache add python3 gcc make musl-dev ${CC}
95

10-
ENV PGDATA=/pg/data
11-
RUN mkdir -p /pg/data && \
6+
RUN if ${CHECK_CODE} -eq "true" && ${CC} -eq "gcc"; then \
7+
echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/main' > /etc/apk/repositories && \
8+
echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/community' >> /etc/apk/repositories && \
9+
apk --no-cache add cppcheck; \
10+
fi && \
11+
pip3 install testgres && \
12+
mkdir -p /pg/data && \
1213
mkdir /pg/pg_pathman && \
1314
chown postgres:postgres ${PGDATA} && \
1415
chmod a+rwx /usr/local/lib/postgresql && \
@@ -18,4 +19,4 @@ ADD . /pg/pg_pathman
1819
WORKDIR /pg/pg_pathman
1920
RUN chmod -R go+rwX /pg/pg_pathman
2021
USER postgres
21-
RUN PGDATA=${PGDATA} CC=${CC} CHECK_CODE=${CHECK_CODE} bash run_tests.sh
22+
ENTRYPOINT PGDATA=${PGDATA} CC=${CC} 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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
id
6+
7+
# perform code analysis if necessary
8+
if [ $CHECK_CODE = "true" ]; then
9+
10+
if [ "$CC" = "clang" ]; then
11+
scan-build --status-bugs make USE_PGXS=1 || status=$?
12+
exit $status
13+
14+
elif [ "$CC" = "gcc" ]; then
15+
cppcheck --template "{file} ({line}): {severity} ({id}): {message}" \
16+
--enable=warning,portability,performance \
17+
--suppress=redundantAssignment \
18+
--suppress=uselessAssignmentPtrArg \
19+
--suppress=incorrectStringBooleanError \
20+
--std=c89 src/*.c src/*.h 2> cppcheck.log
21+
22+
if [ -s cppcheck.log ]; then
23+
cat cppcheck.log
24+
status=1 # error
25+
fi
26+
27+
exit $status
28+
fi
29+
30+
# don't forget to "make clean"
31+
make USE_PGXS=1 clean
32+
fi
33+
34+
# initialize database
35+
initdb
36+
37+
# build pg_pathman (using CFLAGS_SL for gcov)
38+
make USE_PGXS=1 CFLAGS_SL="$(pg_config --cflags_sl) -coverage"
39+
make USE_PGXS=1 install
40+
41+
# check build
42+
status=$?
43+
if [ $status -ne 0 ]; then exit $status; fi
44+
45+
# add pg_pathman to shared_preload_libraries and restart cluster 'test'
46+
echo "shared_preload_libraries = 'pg_pathman'" >> $PGDATA/postgresql.conf
47+
echo "port = 55435" >> $PGDATA/postgresql.conf
48+
pg_ctl start -l /tmp/postgres.log -w
49+
50+
# run regression tests
51+
PGPORT=55435 make USE_PGXS=1 installcheck || status=$?
52+
53+
# show diff if it exists
54+
if test -f regression.diffs; then cat regression.diffs; fi
55+
56+
set +u
57+
58+
# run python tests
59+
make USE_PGXS=1 python_tests || status=$?
60+
if [ $status -ne 0 ]; then exit $status; fi
61+
62+
set -u
63+
64+
# run mock tests (using CFLAGS_SL for gcov)
65+
make USE_PGXS=1 PG_CPPFLAGS="-coverage" cmocka_tests || status=$?
66+
if [ $status -ne 0 ]; then exit $status; fi
67+
68+
# remove useless gcov files
69+
rm -f tests/cmocka/*.gcno
70+
rm -f tests/cmocka/*.gcda
71+
72+
#generate *.gcov files
73+
gcov src/*.c src/compat/*.c src/include/*.h src/include/compat/*.h
74+
75+
exit $status

tests/cmocka/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ TOP_SRC_DIR = ../../src
33

44
CC = gcc
55
CFLAGS += -I $(TOP_SRC_DIR) -I $(shell $(PG_CONFIG) --includedir-server)
6-
CFLAGS += -I$(CURDIR)/../../src/include
6+
CFLAGS += -I$(CURDIR)/../../src/include -I.
77
CFLAGS += $(shell $(PG_CONFIG) --cflags_sl)
88
CFLAGS += $(shell $(PG_CONFIG) --cflags)
99
CFLAGS += $(CFLAGS_SL)
1010
CFLAGS += $(PG_CPPFLAGS)
11-
LDFLAGS = -lcmocka
1211
TEST_BIN = rangeset_tests
1312

1413
OBJ = missing_basic.o missing_list.o missing_stringinfo.o \
15-
missing_bitmapset.o rangeset_tests.o \
14+
missing_bitmapset.o rangeset_tests.o cmockery.o \
1615
$(TOP_SRC_DIR)/rangeset.o
1716

1817

tests/cmocka/cmocka-1.1.1.tar.xz

-83.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)