Skip to content

Commit 25ebf20

Browse files
tests: add utility script run-ci.sh
1 parent 1793b3b commit 25ebf20

File tree

2 files changed

+211
-1
lines changed

2 files changed

+211
-1
lines changed

README.markdown

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Table of Contents
4545
* [Missing data on short circuited requests](#missing-data-on-short-circuited-requests)
4646
* [TODO](#todo)
4747
* [Changes](#changes)
48+
* [Build And Test](#build-and-test)
4849
* [Test Suite](#test-suite)
4950
* [Copyright and License](#copyright-and-license)
5051
* [See Also](#see-also)
@@ -982,6 +983,23 @@ The changes made in every release of this module are listed in the change logs o
982983

983984
[Back to TOC](#table-of-contents)
984985

986+
Build And Test
987+
==============
988+
989+
This module uses `.travis.yml` as the CI configuration.
990+
You can always check `.travis.yml` for the latest CI configuration.
991+
992+
For developers, you need to run tests locally. You can use `util/run-ci.sh`
993+
to easily set up the environment and execute the test suite.
994+
995+
To run the Test from the beginning:
996+
997+
```shell
998+
git clone https://github.com/openresty/lua-nginx-module.git
999+
cd lua-nginx-module
1000+
bash util/run-ci.sh
1001+
```
1002+
9851003
Test Suite
9861004
==========
9871005

@@ -1026,7 +1044,6 @@ To run the whole test suite in the default testing mode:
10261044
export PATH=/path/to/your/nginx/sbin:$PATH
10271045
prove -I/path/to/test-nginx/lib -r t
10281046

1029-
10301047
To run specific test files:
10311048

10321049
cd /path/to/lua-nginx-module

util/run-ci.sh

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
#!/bin/bash
2+
3+
#export CC=clang
4+
export CC=gcc
5+
export NGX_BUILD_CC=$CC
6+
7+
mkdir -p download-cache
8+
9+
export JOBS=$(nproc)
10+
export NGX_BUILD_JOBS=$JOBS
11+
export VALGRIND_INC=/usr/include/valgrind/
12+
13+
export LUAJIT_PREFIX=/opt/luajit21
14+
export LUAJIT_LIB=$LUAJIT_PREFIX/lib
15+
export LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
16+
export LUA_INCLUDE_DIR=$LUAJIT_INC
17+
18+
export PCRE2_VER=10.45
19+
export PCRE2_PREFIX=/opt/pcre2
20+
export PCRE2_LIB=$PCRE2_PREFIX/lib
21+
export PCRE2_INC=$PCRE2_PREFIX/include
22+
23+
export OPENSSL_VER=3.5.0
24+
export OPENSSL_PATCH_VER=3.5.0
25+
export OPENSSL_PREFIX=/opt/ssl3
26+
export OPENSSL_LIB=$OPENSSL_PREFIX/lib
27+
export OPENSSL_INC=$OPENSSL_PREFIX/include
28+
29+
export LIBDRIZZLE_PREFIX=/opt/drizzle
30+
export LIBDRIZZLE_INC=$LIBDRIZZLE_PREFIX/include/libdrizzle-1.0
31+
export LIBDRIZZLE_LIB=$LIBDRIZZLE_PREFIX/lib
32+
export DRIZZLE_VER=2011.07.21
33+
34+
#export TEST_NGINX_SLEEP=0.006
35+
export NGINX_VERSION=1.27.1
36+
#export NGX_BUILD_ASAN=1
37+
38+
export PATH=/opt/bin:$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:$PATH
39+
40+
if [ ! -f /opt/bin/curl ]; then
41+
wget https://github.com/stunnel/static-curl/releases/download/8.14.1/curl-linux-x86_64-glibc-8.14.1.tar.xz
42+
tar -xf curl-linux-x86_64-glibc-8.14.1.tar.xz
43+
tar -xf curl-linux-x86_64-glibc-8.14.1.tar.xz
44+
sudo mkdir -p /opt/bin
45+
sudo mv curl /opt/bin/
46+
fi
47+
48+
function git_download()
49+
{
50+
dir=${!#}
51+
if [ ! -d $dir ]; then
52+
git clone $@
53+
fi
54+
}
55+
56+
function download_deps()
57+
{
58+
if [ ! -f download-cache/drizzle7-$DRIZZLE_VER.tar.gz ]; then
59+
wget -P download-cache https://github.com/openresty/openresty-deps-prebuild/releases/download/v20230902/drizzle7-$DRIZZLE_VER.tar.gz
60+
fi
61+
62+
if [ ! -f download-cache/pcre2-$PCRE2_VER.tar.gz ]; then
63+
wget -P download-cache https://github.com/PCRE2Project/pcre2/releases/download/pcre2-${PCRE2_VER}/pcre2-${PCRE2_VER}.tar.gz
64+
fi
65+
66+
if [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then
67+
wget -P download-cache https://github.com/openssl/openssl/releases/download/openssl-$OPENSSL_VER/openssl-$OPENSSL_VER.tar.gz
68+
fi
69+
70+
git_download clone https://github.com/openresty/test-nginx.git
71+
git_download clone https://github.com/openresty/openresty.git ../openresty
72+
git_download clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx
73+
git_download clone https://github.com/openresty/openresty-devel-utils.git
74+
git_download clone https://github.com/openresty/mockeagain.git
75+
git_download clone https://github.com/openresty/lua-cjson.git lua-cjson
76+
git_download clone https://github.com/openresty/lua-upstream-nginx-module.git ../lua-upstream-nginx-module
77+
git_download clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module
78+
git_download clone https://github.com/openresty/nginx-eval-module.git ../nginx-eval-module
79+
git_download clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module
80+
git_download clone https://github.com/FRiCKLE/ngx_coolkit.git ../coolkit-nginx-module
81+
git_download clone https://github.com/openresty/headers-more-nginx-module.git ../headers-more-nginx-module
82+
git_download clone https://github.com/openresty/drizzle-nginx-module.git ../drizzle-nginx-module
83+
git_download clone https://github.com/openresty/set-misc-nginx-module.git ../set-misc-nginx-module
84+
git_download clone https://github.com/openresty/memc-nginx-module.git ../memc-nginx-module
85+
git_download clone https://github.com/openresty/rds-json-nginx-module.git ../rds-json-nginx-module
86+
git_download clone https://github.com/openresty/srcache-nginx-module.git ../srcache-nginx-module
87+
git_download clone https://github.com/openresty/redis2-nginx-module.git ../redis2-nginx-module
88+
git_download clone https://github.com/openresty/lua-resty-core.git ../lua-resty-core
89+
git_download clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache
90+
git_download clone https://github.com/openresty/lua-resty-mysql.git ../lua-resty-mysql
91+
git_download clone https://github.com/openresty/lua-resty-string.git ../lua-resty-string
92+
git_download clone https://github.com/openresty/stream-lua-nginx-module.git ../stream-lua-nginx-module
93+
git_download clone -b v2.1-agentzh https://github.com/openresty/luajit2.git luajit2
94+
}
95+
96+
function make_deps()
97+
{
98+
if [ "$TEST_NGINX_BUILD_DEPS" = "n" ]; then
99+
return
100+
fi
101+
102+
cd luajit2/
103+
make clean
104+
make -j"$JOBS" CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS="-DLUAJIT_USE_VALGRIND -I$VALGRIND_INC -DLUAJIT_USE_SYSMALLOC -DLUA_USE_APICHECK -DLUA_USE_ASSERT -msse4.2" > build.log 2>&1 || (cat build.log && exit 1)
105+
sudo make install PREFIX=$LUAJIT_PREFIX
106+
cd ..
107+
108+
tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz
109+
cd openssl-$OPENSSL_VER/
110+
patch -p1 < ../../openresty/patches/openssl-$OPENSSL_PATCH_VER-sess_set_get_cb_yield.patch > ssl.log
111+
./config -DOPENSSL_TLS_SECURITY_LEVEL=1 shared enable-ssl3 enable-ssl3-method -g -O2 --prefix=$OPENSSL_PREFIX --libdir=lib -DPURIFY >> ssl.log
112+
make -j$JOBS >> ssl.log
113+
sudo make PATH=$PATH install_sw >> ssl.log
114+
cd ..
115+
116+
tar zxf download-cache/pcre2-$PCRE2_VER.tar.gz;
117+
cd pcre2-$PCRE2_VER/;
118+
./configure --prefix=$PCRE2_PREFIX --enable-jit --enable-utf
119+
sudo PATH=$PATH make install
120+
cd ..
121+
122+
tar xzf download-cache/drizzle7-$DRIZZLE_VER.tar.gz && cd drizzle7-$DRIZZLE_VER
123+
./configure --prefix=$LIBDRIZZLE_PREFIX --without-server
124+
make libdrizzle-1.0 -j$JOBS
125+
sudo make install-libdrizzle-1.0
126+
cd ..
127+
128+
cd mockeagain/ && make CC=$CC -j$JOBS
129+
cd ..
130+
131+
cd lua-cjson/ && make -j$JOBS && sudo make install
132+
cd ..
133+
}
134+
135+
function make_ngx()
136+
{
137+
if [ "$TEST_NGINX_FRESH_BUILD" = "y" ]; then
138+
rm -fr buildroot
139+
fi
140+
141+
sh util/build.sh $NGINX_VERSION 2>&1 | tee build.log
142+
}
143+
144+
download_deps
145+
make_deps
146+
make_ngx
147+
148+
find t -name "*.t" | xargs reindex >/dev/null 2>&1
149+
150+
#nginx -V
151+
152+
export LD_PRELOAD=$PWD/mockeagain/mockeagain.so
153+
export LD_LIBRARY_PATH=$PWD/mockeagain:$LD_LIBRARY_PATH
154+
155+
#export ASAN_OPTIONS=detect_leaks=0,log_path=/tmp/asan/asan,log_exe_name=true
156+
#export LD_PRELOAD=/lib64/libasan.so.5:$PWD/mockeagain/mockeagain.so
157+
158+
export LD_LIBRARY_PATH=$LUAJIT_LIB:$OPENSSL_LIB:$LD_LIBRARY_PATH
159+
export TEST_NGINX_RESOLVER=8.8.4.4
160+
161+
#export TEST_NGINX_NO_CLEAN=1
162+
#export TEST_NGINX_CHECK_LEAK=1
163+
#export TEST_NGINX_CHECK_LEAK_COUNT=100
164+
#export TEST_NGINX_TIMEOUT=5
165+
166+
#export TEST_NGINX_USE_VALGRIND=1
167+
#export TEST_NGINX_VALGRIND_EXIT_ON_FIRST_ERR=1
168+
#export TEST_NGINX_USE_HTTP2=1
169+
170+
export MALLOC_PERTURB_=33
171+
export TEST_NGINX_HTTP3_CRT=$PWD/t/cert/http3/http3.crt
172+
export TEST_NGINX_HTTP3_KEY=$PWD/t/cert/http3/http3.key
173+
#export TEST_NGINX_USE_HTTP3=1
174+
175+
#export TEST_NGINX_VERBOSE=1
176+
177+
#export TEST_NGINX_EVENT_TYPE=poll
178+
#export TEST_NGINX_POSTPONE_OUTPUT=1
179+
#export MOCKEAGAIN=r
180+
#export MOCKEAGAIN=w
181+
#export MOCKEAGAIN=rw
182+
#export MOCKEAGAIN_VERBOSE=1
183+
184+
ldd `which nginx`|grep -E 'luajit|ssl|pcre'
185+
which nginx
186+
nginx -V
187+
188+
#export TEST_NGINX_INIT_BY_LUA="debug.sethook(function () collectgarbage() end, 'l') jit.off() package.path = '/usr/share/lua/5.1/?.lua;$PWD/../lua-resty-core/lib/?.lua;$PWD/../lua-resty-lrucache/lib/?.lua;' .. (package.path or '') require 'resty.core' require('resty.core.base').set_string_buf_size(1) require('resty.core.regex').set_buf_grow_ratio(1)"
189+
190+
191+
# comment out TEST_NGINX_RANDOMIZE when debugging one test case
192+
export TEST_NGINX_RANDOMIZE=1
193+
prove -j$JOBS -I. -Itest-nginx/inc -Itest-nginx/lib -r t/

0 commit comments

Comments
 (0)