Skip to content

Commit

Permalink
chore(*) isolate test suites by Wasm target
Browse files Browse the repository at this point in the history
* Remove WASI spillover from test crates compatible with the
  `wasm32-unknown-unknown` target.
* Default all tests crates to compile `wasm32-wasip1` targets.
* Can set `TEST_NGINX_CARGO_RUSTTARGET` to override.
* Cleanup build tests framework.
* CI: add a job with `wasm32-unknown-unknown` target.
  • Loading branch information
thibaultcha committed Sep 24, 2024
1 parent f8d79ee commit ca50074
Show file tree
Hide file tree
Showing 30 changed files with 86 additions and 198 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ jobs:
ssl: ssl
debug: debug
hup: no_hup
# wasm32-unknown-unknown
- runtime: wasmtime
wasmtime: 23.0.2
os: ubuntu-latest
cc: gcc-12
ngx: 1.27.1
ipc: no_ipc
ssl: no_ssl
debug: debug
hup: no_hup
wasm_target: wasm32-unknown-unknown
# Old Nginx
- label: old_nginx
os: ubuntu-latest
Expand Down Expand Up @@ -146,6 +157,7 @@ jobs:
ssl: ${{ matrix.ssl }}
debug: ${{ matrix.debug }}
hup: ${{ matrix.hup }}
wasm_target: ${{ matrix.wasm_target }}
module_type: ${{ matrix.module_type }}
coverage: true
secrets: inherit
Expand All @@ -162,7 +174,7 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
carryforward: 'unit-ngx_1.27.1-wasmer-no_ipc-ssl-debug-no_hup-static,unit-ngx_1.27.1-wasmer-no_ipc-ssl-no_debug-no_hup-static,unit-ngx_1.27.1-wasmtime-no_ipc-ssl-debug-hup-static,unit-ngx_1.27.1-wasmtime-no_ipc-ssl-debug-hup-dynamic,unit-ngx_1.27.1-v8-no_ipc-ssl-debug-no_hup-static,unit-ngx_1.21.6-wasmer-no_ipc-ssl-debug-no_hup-static,unit-ngx_1.27.1-wasmer-no_ipc-no_ssl-no_debug-no_hup-static,unit-openresty_1.25.3.2-wasmtime-no_ipc-ssl-debug-no_hup-static,unit-openresty_1.25.3.2-wasmtime-no_ipc-ssl-debug-no_hup-dynamic,unit-ngx_1.27.1-wasmtime-ipc-no_ssl-debug-no_hup-static'
carryforward: 'unit-ngx_1.27.1-wasmer-no_ipc-ssl-debug-no_hup-static,unit-ngx_1.27.1-wasmer-no_ipc-ssl-no_debug-no_hup-static,unit-ngx_1.27.1-wasmtime-no_ipc-ssl-debug-hup-static,unit-ngx_1.27.1-wasmtime-no_ipc-ssl-debug-hup-dynamic,unit-ngx_1.27.1-v8-no_ipc-ssl-debug-no_hup-static,unit-ngx_1.27.1-wasmtime-no_ipc-no_ssl-debug-no_hup-static-wasm32-unknown-unknown,unit-ngx_1.21.6-wasmer-no_ipc-ssl-debug-no_hup-static,unit-ngx_1.27.1-wasmer-no_ipc-no_ssl-no_debug-no_hup-static,unit-openresty_1.25.3.2-wasmtime-no_ipc-ssl-debug-no_hup-static,unit-openresty_1.25.3.2-wasmtime-no_ipc-ssl-debug-no_hup-dynamic,unit-ngx_1.27.1-wasmtime-ipc-no_ssl-debug-no_hup-static'

valgrind:
name: 'Valgrind'
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/job-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ on:
hup:
required: true
type: string
wasm_target:
required: false
type: string
module_type:
required: true
type: string
Expand All @@ -64,6 +67,7 @@ env:
TEST_NGINX_TIMEOUT: 60
TEST_NGINX_EXTERNAL_TIMEOUT: 60s
TEST_NGINX_EXTERNAL_RESOLVER: 127.0.0.1:8053
TEST_NGINX_CARGO_RUSTTARGET: ${{ inputs.wasm_target }}

jobs:
tests:
Expand Down Expand Up @@ -103,6 +107,10 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-wasip1
- name: Add wasm32-unknown-unknown target
if: ${{ inputs.wasm_target == 'wasm32-unknown-unknown' }}
run: |
rustup target add wasm32-unknown-unknown
- name: Setup Go
if: ${{ !env.ACT }}
uses: actions/setup-go@v5
Expand Down Expand Up @@ -170,6 +178,9 @@ jobs:
else
name="$name-static"
fi
if [ -n "${{ inputs.wasm_target }}" ]; then
name="$name-${{ inputs.wasm_target }}"
fi
echo "name=$name" >> $GITHUB_OUTPUT
- name: Coveralls Upload
if: ${{ !env.ACT && inputs.coverage }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ setup:

.PHONY: test
test:
@util/test.sh t/0*
@util/test.sh t/

.PHONY: test-build
test-build:
Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/000-non_host_wasi.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

our $nginxV = $t::TestWasmX::nginxV;

plan_tests(4);
Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/001-random_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/002-environ_sizes_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/003-environ_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/004-clock_time_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/005-args_sizes_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/006-args_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/007-fd_write.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/008-fd_close.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/009-fd_fdstat_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/010-fd_prestat_get.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/011-fd_prestat_dir_name.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/012-fd_read.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/013-fd_seek.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 2 additions & 0 deletions t/01-wasm/hfuncs/wasi/014-path_open.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use lib '.';
use t::TestWasmX;

skip_no_wasi();

plan_tests(3);
run_tests();

Expand Down
2 changes: 1 addition & 1 deletion t/03-proxy_wasm/hfuncs/101-proxy_get_current_time.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ should produce a log with the current time (ms as ~ns)
--- response_body
ok
--- error_log eval
qr/\[info\] .*? now: 2.*? UTC/,
qr/\[info\] .*? now: SystemTime\(\d+\.\d+s\)/,
--- no_error_log
[error]
2 changes: 1 addition & 1 deletion t/10-build/001-build_options.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use lib '.';
use t::TestBuild;

skip_valgrind();
skip_no_test_nginx();

our $buildroot = $t::TestBuild::buildroot;
our $openssl_ver = get_variable_from_makefile("OPENSSL");
Expand Down
2 changes: 1 addition & 1 deletion t/10-build/002-runtime_linking.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use lib '.';
use t::TestBuild;

skip_valgrind();
skip_no_test_nginx();

our $buildroot = $t::TestBuild::buildroot;

Expand Down
2 changes: 1 addition & 1 deletion t/10-build/003-dynamic_module.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use lib '.';
use t::TestBuild;

skip_valgrind();
skip_no_test_nginx();

our $buildroot = $t::TestBuild::buildroot;

Expand Down
2 changes: 1 addition & 1 deletion t/10-build/004-ngx_wasm_rs_linking.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use lib '.';
use t::TestBuild;

skip_valgrind();
skip_no_test_nginx();

our $buildroot = $t::TestBuild::buildroot;

Expand Down
9 changes: 9 additions & 0 deletions t/TestBuild.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ our $buildroot = $ENV{NGX_BUILD_DIR_BUILDROOT};
our @EXPORT = qw(
$buildroot
skip_valgrind
skip_no_test_nginx
get_variable_from_makefile
run_tests
);
Expand Down Expand Up @@ -45,6 +46,14 @@ sub skip_valgrind {
}
}

sub skip_no_test_nginx {
if (!defined $ENV{TEST_NGINX_NO_TEST_NGINX}
|| $ENV{TEST_NGINX_NO_TEST_NGINX} != 1)
{
plan(skip_all => "skip without build test mode (\$TEST_NGINX_NO_TEST_NGINX=1)");
}
}

sub get_variable_from_makefile($) {
my $name = shift;

Expand Down
7 changes: 7 additions & 0 deletions t/TestWasmX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ our @EXPORT = qw(
skip_no_debug
skip_no_go_sdk
skip_no_assemblyscript_sdk
skip_no_wasi
);

$ENV{TEST_NGINX_USE_HUP} ||= 0;
Expand Down Expand Up @@ -103,6 +104,12 @@ sub skip_no_assemblyscript_sdk {
}
}

sub skip_no_wasi {
if ($ENV{TEST_NGINX_CARGO_RUSTTARGET} !~ m/wasi/) {
plan(skip_all => "skip without WASI target (\$TEST_NGINX_CARGO_RUSTTARGET is set to \"$ENV{TEST_NGINX_CARGO_RUSTTARGET}\")");
}
}

sub load_nginx_modules (@) {
splice @nginx_modules, 0, 0, @_;
}
Expand Down
Loading

0 comments on commit ca50074

Please sign in to comment.