1
1
#! /usr/bin/env bash
2
2
3
3
#
4
- # Copyright (c) 2019-2020 , Postgres Professional
4
+ # Copyright (c) 2019-2021 , Postgres Professional
5
5
#
6
6
7
- PG_SRC=$PWD /postgres
7
+ PTRACK_SRC=${PWD} /ptrack
8
+ PG_SRC=${PWD} /postgres
9
+ PBK_SRC=${PWD} /pg_probackup
8
10
status=0
9
11
10
- # curl "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" -o postgresql.tar.bz2
11
- # echo "$PG_SHA256 *postgresql.tar.bz2" | sha256sum -c -
12
-
13
- # mkdir $PG_SRC
14
-
15
- # tar \
16
- # --extract \
17
- # --file postgresql.tar.bz2 \
18
- # --directory $PG_SRC \
19
- # --strip-components 1
20
-
12
+ # ########################################################
21
13
# Clone Postgres
22
14
echo " ############### Getting Postgres sources"
23
- git clone https://github.com/postgres/postgres.git -b $PG_BRANCH -- depth=1
15
+ git clone https://github.com/postgres/postgres.git -- depth=1 --branch= ${PG_BRANCH} ${PG_SRC}
24
16
25
17
# Clone pg_probackup
26
18
echo " ############### Getting pg_probackup sources"
27
- git clone https://github.com/postgrespro/pg_probackup.git --depth=1 -b master
28
- # git clone https://github.com/ololobus/pg_probackup.git --depth=1 -b ptrack-tests
19
+ git clone https://github.com/postgrespro/pg_probackup.git --depth=1 --branch=master ${PBK_SRC}
29
20
21
+ # ########################################################
30
22
# Compile and install Postgres
31
- cd postgres # Go to postgres dir
23
+ cd ${PG_SRC} # Go to postgres dir
32
24
33
25
echo " ############### Applying ptrack patch"
34
- git apply -v -3 .. /patches/$PG_BRANCH -ptrack-core.diff
26
+ git apply --verbose --3way ${PTRACK_SRC} /patches/${ PG_BRANCH} -ptrack-core.diff
35
27
36
- if [ " $MODE " = " paranoia" ]; then
28
+ if [ " ${ MODE} " = " paranoia" ]; then
37
29
echo " ############### Paranoia mode: applying turn-off-hint-bits.diff"
38
- git apply -v -3 .. /patches/turn-off-hint-bits.diff
30
+ git apply --verbose --3way ${PTRACK_SRC} /patches/turn-off-hint-bits.diff
39
31
fi
40
32
41
33
echo " ############### Compiling Postgres"
42
- if [ " $TEST_CASE " = " tap" ] && [ " $MODE " = " legacy" ]; then
43
- ./configure CFLAGS=' -DEXEC_BACKEND' --disable-atomics --prefix=$PGHOME --enable-debug --enable-cassert --enable-depend --enable-tap-tests
34
+ if [ " ${ TEST_CASE} " = " tap" ] && [ " ${ MODE} " = " legacy" ]; then
35
+ ./configure CFLAGS=' -DEXEC_BACKEND' --disable-atomics --prefix=${ PGHOME} --enable-debug --enable-cassert --enable-depend --enable-tap-tests --quiet
44
36
else
45
- ./configure --prefix=$PGHOME --enable-debug --enable-cassert --enable-depend --enable-tap-tests
37
+ ./configure --prefix=${ PGHOME} --enable-debug --enable-cassert --enable-depend --enable-tap-tests --quiet
46
38
fi
47
- make -s -j $( nproc) install
48
- make -s -j $( nproc) -C contrib/ install
39
+ make --quiet --jobs= $( nproc) install
40
+ make --quiet --jobs= $( nproc) --directory= contrib/ install
49
41
50
42
# Override default Postgres instance
51
- export PATH=$PGHOME /bin:$PATH
52
- export LD_LIBRARY_PATH=$PGHOME /lib
43
+ export PATH=${ PGHOME} /bin:${ PATH}
44
+ export LD_LIBRARY_PATH=${ PGHOME} /lib
53
45
export PG_CONFIG=$( which pg_config)
54
46
55
47
# Show pg_config path (just in case)
@@ -60,48 +52,37 @@ which pg_config
60
52
echo " ############### pg_config"
61
53
pg_config
62
54
63
- # Get amcheck if missing
64
- if [ ! -d " contrib/amcheck" ]; then
65
- echo " ############### Getting missing amcheck"
66
- git clone https://github.com/petergeoghegan/amcheck.git --depth=1 contrib/amcheck
67
- make USE_PGXS=1 -C contrib/amcheck install
68
- fi
69
-
70
- # Get back to testdir
71
- cd ..
72
-
55
+ # ########################################################
73
56
# Build and install ptrack extension
74
57
echo " ############### Compiling and installing ptrack extension"
58
+ cp --recursive ${PTRACK_SRC} ${PG_SRC} /contrib/ptrack
59
+ make USE_PGXS=1 PG_CPPFLAGS=" -coverage" SHLIB_LINK=" -coverage" --directory=${PG_SRC} /contrib/ptrack/ install
75
60
76
- # XXX: Hackish way to make possible to run tap tests
77
- mkdir $PG_SRC /contrib/ptrack
78
- cp * $PG_SRC /contrib/ptrack/
79
- cp -R t $PG_SRC /contrib/ptrack/
80
-
81
- make USE_PGXS=1 PG_CPPFLAGS=" -coverage" SHLIB_LINK=" -coverage" -C $PG_SRC /contrib/ptrack/ install
82
-
83
- if [ " $TEST_CASE " = " tap" ]; then
61
+ if [ " ${TEST_CASE} " = " tap" ]; then
84
62
85
63
# Run tap tests
86
64
echo " ############### Running tap tests"
87
- if [ " $MODE " = " legacy" ]; then
65
+ if [ " ${ MODE} " = " legacy" ]; then
88
66
# There is a known issue with attaching shared memory segment using the same
89
67
# address each time, when EXEC_BACKEND mechanism is turned on. It happens due
90
68
# to the ASLR address space randomization, so we are trying to attach a segment
91
69
# to the already occupied location. That way we simply turning off ASLR here.
92
70
#
93
71
# Postgres comment: https://github.com/postgres/postgres/blob/5cbfce562f7cd2aab0cdc4694ce298ec3567930e/src/backend/postmaster/postmaster.c#L4929
94
- setarch x86_64 --addr-no-randomize make -C postgres /contrib/ptrack check || status=$?
72
+ setarch x86_64 --addr-no-randomize make --directory= ${PG_SRC} /contrib/ptrack check || status=$?
95
73
else
96
- make -C postgres /contrib/ptrack check || status=$?
74
+ make --directory= ${PG_SRC} /contrib/ptrack check || status=$?
97
75
fi
98
76
99
77
else
78
+ # Set kernel params (used for debugging -- probackup tests)
79
+ echo " ############### setting kernel params"
80
+ sudo sh -c ' echo 0 > /proc/sys/kernel/yama/ptrace_scope'
100
81
101
82
# Build and install pg_probackup
102
83
echo " ############### Compiling and installing pg_probackup"
103
- cd pg_probackup # Go to pg_probackup dir
104
- make USE_PGXS=1 top_srcdir=$PG_SRC install
84
+ cd ${PBK_SRC} # Go to pg_probackup dir
85
+ make USE_PGXS=1 top_srcdir=${ PG_SRC} install
105
86
106
87
# Setup python environment
107
88
echo " ############### Setting up python env"
@@ -110,35 +91,36 @@ else
110
91
pip install testgres==1.8.2
111
92
112
93
echo " ############### Testing"
113
- if [ " $MODE " = " basic" ]; then
94
+ export PG_PROBACKUP_PTRACK=ON
95
+ if [ " ${MODE} " = " basic" ]; then
114
96
export PG_PROBACKUP_TEST_BASIC=ON
115
- elif [ " $MODE " = " paranoia" ]; then
97
+ elif [ " ${ MODE} " = " paranoia" ]; then
116
98
export PG_PROBACKUP_PARANOIA=ON
117
99
fi
118
100
119
- export PG_PROBACKUP_PTRACK=ON
120
- if [ " $TEST_CASE " = " all" ]; then
101
+ if [ " ${TEST_CASE} " = " all" ]; then
121
102
# Run all pg_probackup ptrack tests
122
- python3 -m unittest -v tests.ptrack || status= $?
103
+ PBK_TEST_CASE= tests.ptrack
123
104
else
124
- for i in ` seq $TEST_REPEATS ` ; do
125
- python3 -m unittest -v tests.ptrack.PtrackTest.$TEST_CASE || status=$?
126
- done
105
+ PBK_TEST_CASE=tests.ptrack.PtrackTest.${TEST_CASE}
127
106
fi
107
+ for i in ` seq ${TEST_REPEATS} ` ; do
108
+ python3 -m unittest -v ${PBK_TEST_CASE} || status=$?
109
+ done
128
110
129
111
# Exit virtualenv
130
112
deactivate
131
-
132
- # Get back to testdir
133
- cd ..
134
-
135
113
fi
136
114
115
+ # ########################################################
116
+ # codecov
117
+ echo " ############### Codecov"
118
+ cd ${PTRACK_SRC}
137
119
# Generate *.gcov files
138
- gcov $PG_SRC /contrib/ptrack/* .c $PG_SRC /contrib/ptrack/* .h
120
+ gcov ${ PG_SRC} /contrib/ptrack/* .c ${ PG_SRC} /contrib/ptrack/* .h
139
121
140
122
# Send coverage stats to Codecov
141
123
bash <( curl -s https://codecov.io/bash)
142
124
143
125
# Something went wrong, exit with code 1
144
- if [ $status -ne 0 ]; then exit 1; fi
126
+ if [ ${ status} -ne 0 ]; then exit 1; fi
0 commit comments