-
Notifications
You must be signed in to change notification settings - Fork 58
247 lines (223 loc) · 9.07 KB
/
sanitizer-build-and-test.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# Run tests with sanitizers enabled
# derived from from https://github.com/timescale/timescaledb/blob/main/.github/workflows/sanitizer-build-and-test.yaml
name: Sanitizer test
on:
push:
branches:
- main
- trigger/sanitizer
pull_request:
branches:
- main
release:
types: [created, edited]
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run the build against llvm sanitizers"
required: false
default: false
env:
name: "Sanitizer"
PG_SRC_DIR: "pgbuild"
PG_INSTALL_DIR: ${{ github.workspace }}/pgsql
extra_packages: "clang-15 llvm-15 llvm-15-dev llvm-15-tools"
llvm_config: "llvm-config-15"
CLANG: "clang-15"
CC: "clang-15"
CXX: "clang-15"
CFLAGS: "-g -fsanitize=address -fno-omit-frame-pointer -Og -fno-inline-functions"
CXXFLAGS: "-g -fsanitize=address -fno-omit-frame-pointer -Og -fno-inline-functions"
LDFLAGS: "-fsanitize=address"
ASAN_OPTIONS: suppressions=${{ github.workspace }}/lantern_hnsw/scripts/sanitizers/suppressions/suppr_asan.txt
detect_odr_violation=0 log_path=${{ github.workspace }}/sanitizer/
log_exe_name=true print_suppressions=false exitcode=27
detect_leaks=0 abort_on_error=1
LSAN_OPTIONS: suppressions=${{ github.workspace }}/lantern_hnsw/scripts/sanitizers/suppressions/suppr_leak.txt
print_suppressions=0 log_path=${{ github.workspace }}/sanitizer/
log_exe_name=true print_suppressions=false exitcode=27
UBSAN_OPTIONS: suppressions=${{ github.workspace }}/lantern_hnsw/scripts/sanitizers/suppressions/suppr_ub.txt
print_stacktrace=1 halt_on_error=1 log_path=${{ github.workspace }}/sanitizer/
log_exe_name=true print_suppressions=false exitcode=27
jobs:
sanitizer:
# Change the JOB_NAME variable below when changing the name.
# Don't use the env variable here because the env context is not accessible.
name: PG${{ matrix.pg }} Sanitizer ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-22.04"]
pg: ["12.16", "13.12", "14.9", "15.4", "16.0", "17.0"]
steps:
- name: Enable UBSan if this is a release
if: ${{ github.event_name == 'release' }}
run: |
echo "CFLAGS=\"\-g -fsanitize=address,undefined -fno-omit-frame-pointer -O0 -fno-inline-functions"" >> $GITHUB_ENV
echo "CXXFLAGS=\"\-g -fsanitize=address,undefined -fno-omit-frame-pointer -O0 -fno-inline-functions"" >> $GITHUB_ENV
echo "LDFLAGS=\"-fsanitize=address,undefined\"" >> $GITHUB_ENV
- name: Install Linux Dependencies
run: |
sudo apt-get update
sudo apt-get install -y wget \
curl \
systemd-coredump \
build-essential \
gdb \
make \
cmake \
pkg-config \
flex \
bison \
libicu-dev \
libssl-dev \
clang-15 \
llvm-15 \
llvm-15-dev \
llvm-15-tools \
libstdc++-12-dev \
libstdc++6
- name: Checkout lantern
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: "recursive"
# We are going to rebuild Postgres daily, so that it doesn't suddenly break
# ages after the original problem.
- name: Get date for build caching
id: get-date
run: |
echo "date=$(date +"%m-%y")" >> $GITHUB_OUTPUT
# Create a directory for sanitizer logs. This directory is referenced by
# ASAN_OPTIONS, LSAN_OPTIONS, and UBSAN_OPTIONS
- name: Create sanitizer log directory
run: |
mkdir ${{ github.workspace }}/sanitizer
# we cache the build directory instead of the install directory here
# because extension installation will write files to install directory
# leading to a tainted cache
- name: Cache PostgreSQL ${{ matrix.pg }}
id: cache-postgresql
uses: actions/cache@v4
with:
path: ~/${{ env.PG_SRC_DIR }}
key: "${{ matrix.os }}-${{ env.name }}-postgresql-${{ matrix.pg }}-${{ env.CC }}\
-${{ steps.get-date.outputs.date }}-${{ hashFiles('.github/**') }}"
- name: Build PostgreSQL ${{ matrix.pg }} if not in cache
id: build-postgresql
if: steps.cache-postgresql.outputs.cache-hit != 'true'
run: |
wget -q -O postgresql.tar.bz2 \
https://ftp.postgresql.org/pub/source/v${{ matrix.pg }}/postgresql-${{ matrix.pg }}.tar.bz2
mkdir -p ~/$PG_SRC_DIR
tar --extract --file postgresql.tar.bz2 --directory ~/$PG_SRC_DIR --strip-components 1
# Add instrumentation to the Postgres memory contexts. For more details, see
# https://www.postgresql.org/message-id/CAM-w4HNH7%2BU9jZevpVK7Wr49tkfpWSR6wav0RLYrq0HWuP5cxw%40mail.gmail.com
patch -F5 -p1 -d ~/$PG_SRC_DIR < lantern_hnsw/scripts/sanitizers/postgres-asan-instrumentation.patch
cd ~/$PG_SRC_DIR
./configure --prefix=$PG_INSTALL_DIR --enable-debug --enable-cassert \
--with-openssl --without-readline --without-zlib --without-libxml
make -j$(nproc)
make -j$(nproc) -C contrib/pageinspect
make -j$(nproc) -C src/test/isolation
echo "exit_code=$?" >> $GITHUB_OUTPUT
- name: save cache preemptively if postgres built
uses: actions/cache/save@v4
if: steps.build-postgresql.outputs.exit_code == 0
with:
path: ~/${{ env.PG_SRC_DIR }}
key: "${{ matrix.os }}-${{ env.name }}-postgresql-${{ matrix.pg }}-${{ env.CC }}\
-${{ steps.get-date.outputs.date }}-${{ hashFiles('.github/**') }}"
- name: Upload config.log
if: always() && steps.cache-postgresql.outputs.cache-hit != 'true'
uses: actions/upload-artifact@v4
with:
name: config.log for PostgreSQL ${{ matrix.os }} ${{ matrix.name }} ${{ matrix.pg }}
path: ~/${{ env.PG_SRC_DIR }}/config.log
- name: Install PostgreSQL ${{ matrix.pg }}
run: |
make -C ~/$PG_SRC_DIR install
echo $PG_INSTALL_DIR/bin >> $GITHUB_PATH
sudo chmod -R 755 $PG_INSTALL_DIR/bin
$PG_INSTALL_DIR/bin/pg_config --version
- name: Build Lantern
run: |
mkdir lantern_hnsw/lantern_build
cd lantern_hnsw/lantern_build
CXXFLAG="" cmake ..
make install
- name: Start Postgres
run: |
mkdir -p $PG_INSTALL_DIR/data
#sudo chown -R postgres:postgres $PG_INSTALL_DIR/data
#sudo chown -R postgres:postgres ${{ github.workspace }}/sanitizer
#getent group postgres || sudo groupadd postgres
#id -u postgres &>/dev/null || sudo useradd -g postgres postgres
initdb -A trust -D $PG_INSTALL_DIR/data
postgres -D $PG_INSTALL_DIR/data >/tmp/postgres.log 2>&1 &
- name: make test
run: |
cd lantern_hnsw/lantern_build
make test
- name: Show regression diffs
if: always()
id: collectlogs
run: |
find /tmp/lantern -name regression.diffs -exec cat {} + > regression.log
cp /tmp/postgres.log .
if [[ "${{ runner.os }}" == "Linux" ]] ; then
# wait in case there are in-progress coredumps
sleep 10
if coredumpctl -q list >/dev/null; then echo "coredumps=true" >>$GITHUB_OUTPUT; fi
# print OOM killer information
sudo journalctl --system -q --facility=kern --grep "Killed process" || true
fi
if [[ -s regression.log ]]; then echo "regression_diff=true" >>$GITHUB_OUTPUT; fi
#grep -e 'FAILED' -e 'failed (ignored)' installcheck.log || true
cat regression.log
- name: Save regression diffs
if: always() && steps.collectlogs.outputs.regression_diff == 'true'
uses: actions/upload-artifact@v4
with:
name: Regression diff ${{ matrix.os }} ${{ env.name }} ${{ matrix.pg }}
path: |
regression.log
- name: Save postgres log
if: always() && steps.collectlogs.outputs.regression_diff == 'true'
uses: actions/upload-artifact@v4
with:
name: Postgres log ${{ matrix.os }} ${{ env.name }} ${{ matrix.pg }}
path: |
postgres.log
- name: Stack trace
if: always() && steps.collectlogs.outputs.coredumps == 'true'
run: |
sudo coredumpctl gdb <<<"
set verbose on
set trace-commands on
show debug-file-directory
printf "'"'"query = '%s'\n\n"'"'", debug_query_string
frame function ExceptionalCondition
printf "'"'"condition = '%s'\n"'"'", conditionName
up 1
l
info args
info locals
bt full
" 2>&1 | tee stacktrace.log
./lantern_hnsw/scripts/sanitizers/bundle_coredump.sh
grep -C40 "was terminated by signal" postgres.log > postgres-failure.log ||:
- name: Coredumps
if: always() && steps.collectlogs.outputs.coredumps == 'true'
uses: actions/upload-artifact@v4
with:
name: Coredumps ${{ matrix.os }} ${{ env.name }} ${{ matrix.pg }}
path: coredumps
- name: sanitizer logs
if: always()
uses: actions/upload-artifact@v4
with:
name: sanitizer logs ${{ matrix.os }} ${{ env.name }} ${{ matrix.pg }}
path: ${{ github.workspace }}/sanitizer