Skip to content

Commit 52e75d1

Browse files
u5surfzhuizhuhaomeng
authored andcommitted
tests: add an ASan job running the whole test suite.
1 parent f039836 commit 52e75d1

1 file changed

Lines changed: 53 additions & 3 deletions

File tree

‎.github/workflows/build_and_test.yml‎

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8+
workflow_dispatch:
89

910
jobs:
1011
test:
@@ -35,6 +36,13 @@ jobs:
3536
TEST_NGINX_USE_HTTP3: "1"
3637
TEST_NGINX_QUIC_IDLE_TIMEOUT: "3"
3738

39+
- name: "nginx 1.31.6 + OpenSSL + ASan"
40+
NGINX_VERSION: "1.31.6"
41+
# ASan slows every request down, so allow more time than the
42+
# other jobs before a test is called timed out.
43+
TEST_NGINX_TIMEOUT: "10"
44+
ASAN: "1"
45+
3846
services:
3947
redis:
4048
image: redis:7-alpine
@@ -229,8 +237,14 @@ jobs:
229237
- name: Build LuaJIT
230238
run: |
231239
cd luajit2
240+
XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT -msse4.2'
241+
if [ "${{ matrix.ASAN }}" = "1" ]; then
242+
# LuaJIT's own allocator hides use-after-free on Lua objects from
243+
# ASan, since the memory is never returned to the C allocator.
244+
XCFLAGS="$XCFLAGS -DLUAJIT_USE_SYSMALLOC"
245+
fi
232246
make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC \
233-
XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT -msse4.2' \
247+
XCFLAGS="$XCFLAGS" \
234248
> build.log 2>&1 || (cat build.log && exit 1)
235249
sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1)
236250
@@ -261,8 +275,11 @@ jobs:
261275
export LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
262276
export PATH=$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:/opt/curl/bin:$PATH
263277
export NGX_BUILD_CC=$CC
264-
sh util/build-without-ssl.sh ${{ matrix.NGINX_VERSION }} > build.log 2>&1 || (cat build.log && exit 1)
265-
sh util/build-with-dd.sh ${{ matrix.NGINX_VERSION }} > build.log 2>&1 || (cat build.log && exit 1)
278+
export NGX_BUILD_ASAN="${{ matrix.ASAN }}"
279+
if [ "${{ matrix.ASAN }}" != "1" ]; then
280+
sh util/build-without-ssl.sh ${{ matrix.NGINX_VERSION }} > build.log 2>&1 || (cat build.log && exit 1)
281+
sh util/build-with-dd.sh ${{ matrix.NGINX_VERSION }} > build.log 2>&1 || (cat build.log && exit 1)
282+
fi
266283
rm -fr buildroot
267284
sh util/build.sh ${{ matrix.NGINX_VERSION }} > build.log 2>&1 || (cat build.log && exit 1)
268285
nginx -V
@@ -289,7 +306,40 @@ jobs:
289306
[ -n "${{ matrix.TEST_NGINX_QUIC_IDLE_TIMEOUT }}" ] \
290307
&& echo "TEST_NGINX_QUIC_IDLE_TIMEOUT=${{ matrix.TEST_NGINX_QUIC_IDLE_TIMEOUT }}" >> $GITHUB_ENV || true
291308
309+
- name: Run tests under ASan
310+
if: matrix.ASAN == '1'
311+
run: |
312+
export LD_LIBRARY_PATH=$LUAJIT_LIB:$PWD/mockeagain:$LD_LIBRARY_PATH
313+
export PATH=$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:/opt/curl/bin:$PATH
314+
# The ASan runtime has to come first in the preload list: ASan refuses
315+
# to start behind another library, and some test files put mockeagain
316+
# there themselves.
317+
export LD_PRELOAD=$($CC -print-file-name=libasan.so):$PWD/mockeagain/mockeagain.so
318+
export TEST_NGINX_HTTP3_CRT=$PWD/t/cert/http3/http3.crt
319+
export TEST_NGINX_HTTP3_KEY=$PWD/t/cert/http3/http3.key
320+
# Resolve through the local dnsmasq cache, as the other job does.
321+
export TEST_NGINX_RESOLVER=127.0.0.1
322+
export TEST_NGINX_OPENRESTY_ORG_IP=$(dig +short @127.0.0.1 openresty.org | head -n1)
323+
mkdir -p asan-logs
324+
export ASAN_OPTIONS=detect_leaks=0,log_path=$PWD/asan-logs/asan,log_exe_name=true
325+
python3 ./util/nc_server.py &
326+
# ASan replaces the allocator, so glibc's malloc_trim() has nothing to
327+
# give back and t/146-malloc-trim.t sees it return 0 where it expects
328+
# 1. Run every other file.
329+
find t -name '*.t' ! -name '146-malloc-trim.t' -print0 | sort -z \
330+
| xargs -0 /usr/bin/env perl $(command -v prove) -I. -Itest-nginx/inc -Itest-nginx/lib
331+
332+
- name: Show ASan reports
333+
if: matrix.ASAN == '1' && failure()
334+
run: |
335+
shopt -s nullglob
336+
for f in asan-logs/*; do
337+
echo "===== $f"
338+
cat "$f"
339+
done
340+
292341
- name: Run tests
342+
if: matrix.ASAN != '1'
293343
run: |
294344
export LD_LIBRARY_PATH=$LUAJIT_LIB:$PWD/mockeagain:$LD_LIBRARY_PATH
295345
export PATH=$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:/opt/curl/bin:$PATH

0 commit comments

Comments
 (0)