diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ea8a44ef..73d30203e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -147,7 +147,7 @@ jobs: strategy: fail-fast: false matrix: - label: [""] + label: ["wasmer_full"] os: [ubuntu-22.04] cc: [gcc-12] ngx: [1.25.3] @@ -158,6 +158,7 @@ jobs: v8: [""] hup: [no_hup, hup] debug: [debug] + path: [""] include: # Wasmtime - runtime: wasmtime @@ -167,6 +168,7 @@ jobs: ngx: 1.25.3 hup: no_hup debug: debug + path: t/01-wasm # V8 - runtime: v8 v8: 11.4.183.23 @@ -175,16 +177,38 @@ jobs: ngx: 1.25.3 debug: debug hup: no_hup + path: t/01-wasm # OpenResty - label: openresty + runtime: wasmer + wasmer: 3.1.1 os: ubuntu-22.04 cc: gcc-12 openresty: 1.21.4.2 ngx: + debug: debug + hup: no_hup + path: t/04-openresty + # Wasmtime hfuncs + - label: wasmtime_hfuncs + runtime: wasmtime + wasmtime: 14.0.3 + os: ubuntu-22.04 + cc: gcc-12 + ngx: 1.25.3 + hup: no_hup + debug: debug + path: t/03-proxy_wasm/hfuncs + # Wasmer hfuncs + - label: wasmer_hfuncs runtime: wasmer wasmer: 3.1.1 - debug: debug + os: ubuntu-22.04 + cc: gcc-12 + ngx: 1.25.3 hup: no_hup + debug: debug + path: t/03-proxy_wasm/hfuncs uses: ./.github/workflows/job-valgrind-tests.yml with: os: ${{ matrix.os }} @@ -197,6 +221,7 @@ jobs: v8: ${{ matrix.v8 }} hup: ${{ matrix.hup }} debug: ${{ matrix.debug }} + path: ${{ matrix.path }} secrets: inherit lint: diff --git a/.github/workflows/job-valgrind-tests.yml b/.github/workflows/job-valgrind-tests.yml index 759ba350d..bc4e5a417 100644 --- a/.github/workflows/job-valgrind-tests.yml +++ b/.github/workflows/job-valgrind-tests.yml @@ -33,6 +33,9 @@ on: hup: required: true type: string + path: + required: false + type: string defaults: run: @@ -46,8 +49,9 @@ env: NGX_BUILD_CC_OPT: '-O2' NGX_BUILD_NOPOOL: 1 TEST_NGINX_USE_VALGRIND: 1 + TEST_NGINX_USE_VALGRIND_ALL: ${{ inputs.path == '' && 0 || 1 }} TEST_NGINX_USE_HUP: ${{ inputs.hup == 'hup' && 1 || 0 }} - TEST_NGINX_RANDOMIZE: 1 + TEST_NGINX_RANDOMIZE: 0 TEST_NGINX_NO_CLEAN: 1 TEST_NGINX_TIMEOUT: 120 TEST_NGINX_EXTERNAL_TIMEOUT: 120s @@ -101,7 +105,10 @@ jobs: ghcr_password: ${{ secrets.TOKEN_GITHUB }} - run: make setup - run: make - - run: make test 2>&1 | tee valgrind.out + - name: Run tests + run: | + IN_PATH="${{ inputs.path }}" + ./util/test.sh ${IN_PATH:-t/} 2>&1 | tee valgrind.out - run: | awk -f ./util/parse-valgrind.awk valgrind.out > valgrind.log if [[ -s valgrind.log ]]; then diff --git a/Cargo.lock b/Cargo.lock index c2077db5b..3c66063c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,6 +168,14 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" +[[package]] +name = "context-checks" +version = "0.1.0" +dependencies = [ + "log", + "proxy-wasm 0.2.1", +] + [[package]] name = "core-foundation-sys" version = "0.8.4" diff --git a/Cargo.toml b/Cargo.toml index 0aa52f776..e005eb0ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "t/lib/proxy-wasm-tests/rust-sdk-ver-zero-one", "t/lib/proxy-wasm-tests/benchmarks", "t/lib/proxy-wasm-tests/instance-lifecycle", + "t/lib/proxy-wasm-tests/context-checks", ] exclude = [ "lib/ngx-wasm-rs", diff --git a/src/common/proxy_wasm/ngx_proxy_wasm.c b/src/common/proxy_wasm/ngx_proxy_wasm.c index f3c1d9e81..287091f98 100644 --- a/src/common/proxy_wasm/ngx_proxy_wasm.c +++ b/src/common/proxy_wasm/ngx_proxy_wasm.c @@ -501,6 +501,7 @@ action2rc(ngx_proxy_wasm_ctx_t *pwctx, case NGX_HTTP_REWRITE_PHASE: case NGX_HTTP_ACCESS_PHASE: case NGX_HTTP_CONTENT_PHASE: + case NGX_WASM_BACKGROUND_PHASE: ngx_log_debug6(NGX_LOG_DEBUG_WASM, pwctx->log, 0, "proxy_wasm pausing in \"%V\" phase " "(filter: %l/%l, step: %d, action: %d, " @@ -683,6 +684,7 @@ ngx_proxy_wasm_run_step(ngx_proxy_wasm_exec_t *pwexec, ngx_int_t rc; ngx_proxy_wasm_err_e ecode; ngx_proxy_wasm_action_e action = NGX_PROXY_WASM_ACTION_CONTINUE; + ngx_proxy_wasm_exec_t *out; ngx_proxy_wasm_ctx_t *pwctx = pwexec->parent; ngx_proxy_wasm_filter_t *filter = pwexec->filter; #if (NGX_DEBUG) @@ -700,10 +702,12 @@ ngx_proxy_wasm_run_step(ngx_proxy_wasm_exec_t *pwexec, if (pwexec->ictx == NULL || pwexec->ictx->instance->trapped) { #endif ecode = ngx_proxy_wasm_create_context(filter, pwctx, pwexec->id, - pwexec, NULL); + pwexec, &out); if (ecode != NGX_PROXY_WASM_ERR_NONE) { return ecode; } + + pwexec = out; #if 1 } #endif @@ -842,6 +846,9 @@ get_instance(ngx_proxy_wasm_filter_t *filter, dd("get instance in store: %p", store); + /* store initialized */ + ngx_wasm_assert(store->pool); + for (q = ngx_queue_head(&store->busy); q != ngx_queue_sentinel(&store->busy); q = ngx_queue_next(q)) @@ -988,9 +995,6 @@ ngx_proxy_wasm_create_context(ngx_proxy_wasm_filter_t *filter, ictx = in->ictx; } else { - /* store initialized */ - ngx_wasm_assert(store->pool); - ictx = get_instance(filter, store, log); if (ictx == NULL) { goto error; @@ -1187,10 +1191,15 @@ ngx_proxy_wasm_create_context(ngx_proxy_wasm_filter_t *filter, pwexec->started = 1; } - } - if (out) { - *out = pwexec; + if (out) { + *out = pwexec; + } + + } else { + if (out) { + *out = rexec; + } } return NGX_PROXY_WASM_ERR_NONE; @@ -1245,19 +1254,9 @@ ngx_proxy_wasm_on_done(ngx_proxy_wasm_exec_t *pwexec) pwexec->index + 1, pwexec->parent->nfilters); #if 0 - /** - * Currently, dispatches are synchronous hence will always - * have been executed when on_done is invoked. - */ #ifdef NGX_WASM_HTTP call = pwexec->call; if (call) { - ngx_log_debug3(NGX_LOG_DEBUG_WASM, pwexec->log, 0, - "proxy_wasm \"%V\" filter (%l/%l) " - "cancelling HTTP dispatch", - pwexec->filter->name, pwexec->index + 1, - pwexec->parent->nfilters); - ngx_http_proxy_wasm_dispatch_destroy(call); pwexec->call = NULL; diff --git a/src/common/proxy_wasm/ngx_proxy_wasm_host.c b/src/common/proxy_wasm/ngx_proxy_wasm_host.c index a5be0a1a3..cefc27346 100644 --- a/src/common/proxy_wasm/ngx_proxy_wasm_host.c +++ b/src/common/proxy_wasm/ngx_proxy_wasm_host.c @@ -26,21 +26,42 @@ static ngx_int_t ngx_proxy_wasm_hfuncs_no_http(ngx_wavm_instance_t *instance, static ngx_chain_t * ngx_proxy_wasm_get_buffer_helper(ngx_wavm_instance_t *instance, - ngx_proxy_wasm_buffer_type_e buf_type, unsigned *none) + ngx_proxy_wasm_buffer_type_e buf_type, unsigned *none, char **trapmsg) { #ifdef NGX_WASM_HTTP ngx_chain_t *cl; ngx_http_wasm_req_ctx_t *rctx; ngx_http_request_t *r; + ngx_proxy_wasm_ctx_t *pwctx; + ngx_proxy_wasm_exec_t *pwexec; - rctx = ngx_http_proxy_wasm_get_rctx(instance); - r = rctx->r; + pwexec = ngx_proxy_wasm_instance2pwexec(instance); + pwctx = pwexec->parent; #endif switch (buf_type) { #ifdef NGX_WASM_HTTP case NGX_PROXY_WASM_BUFFER_HTTP_REQUEST_BODY: + + /* check context */ + + switch (pwctx->step) { + case NGX_PROXY_WASM_STEP_REQ_HEADERS: + case NGX_PROXY_WASM_STEP_REQ_BODY: + case NGX_PROXY_WASM_STEP_LOG: + break; + default: + *trapmsg = "can only get request body during " + "\"on_request_body\", \"on_log\""; + return NULL; + } + + /* get */ + + rctx = ngx_http_proxy_wasm_get_rctx(instance); + r = rctx->r; + if (r->request_body == NULL || r->request_body->bufs == NULL) { @@ -61,6 +82,23 @@ ngx_proxy_wasm_get_buffer_helper(ngx_wavm_instance_t *instance, return r->request_body->bufs; case NGX_PROXY_WASM_BUFFER_HTTP_RESPONSE_BODY: + + /* check context */ + + switch (pwctx->step) { + case NGX_PROXY_WASM_STEP_RESP_BODY: + case NGX_PROXY_WASM_STEP_LOG: + break; + default: + *trapmsg = "can only get response body during " + "\"on_response_body\", \"on_log\""; + return NULL; + } + + /* get */ + + rctx = ngx_http_proxy_wasm_get_rctx(instance); + cl = rctx->resp_chunk; if (cl == NULL) { /* no body */ @@ -74,9 +112,21 @@ ngx_proxy_wasm_get_buffer_helper(ngx_wavm_instance_t *instance, { ngx_wasm_http_reader_ctx_t *reader; ngx_http_proxy_wasm_dispatch_t *call; - ngx_proxy_wasm_exec_t *pwexec; - pwexec = ngx_proxy_wasm_instance2pwexec(instance); + /* check context */ + + switch (pwctx->step) { + case NGX_PROXY_WASM_STEP_DISPATCH_RESPONSE: + case NGX_PROXY_WASM_STEP_LOG: + break; + default: + *trapmsg = "can only get dispatch response body during " + "\"on_http_dispatch_response\""; + return NULL; + } + + /* get */ + call = pwexec->call; if (call == NULL) { return NULL; @@ -207,11 +257,10 @@ ngx_proxy_wasm_hfuncs_set_tick_period(ngx_wavm_instance_t *instance, ngx_event_t *ev; ngx_proxy_wasm_exec_t *rexec = ngx_proxy_wasm_instance2pwexec(instance); - ngx_wasm_assert(rexec->root_id == NGX_PROXY_WASM_ROOT_CTX_ID); - if (rexec->root_id != NGX_PROXY_WASM_ROOT_CTX_ID) { - /* ignore */ - return ngx_proxy_wasm_result_ok(rets); + return ngx_proxy_wasm_result_trap(rexec, + "can only set tick_period in " + "root context", rets, NGX_WAVM_OK); } if (ngx_exiting) { @@ -254,6 +303,7 @@ ngx_proxy_wasm_hfuncs_get_buffer(ngx_wavm_instance_t *instance, { size_t offset, max_len, len, chunk_len; unsigned none = 0; + char *trapmsg = NULL; u_char *start = NULL; ngx_chain_t *cl = NULL; ngx_buf_t *buf; @@ -282,8 +332,14 @@ ngx_proxy_wasm_hfuncs_get_buffer(ngx_wavm_instance_t *instance, break; default: - cl = ngx_proxy_wasm_get_buffer_helper(instance, buf_type, &none); + cl = ngx_proxy_wasm_get_buffer_helper(instance, buf_type, &none, + &trapmsg); if (cl == NULL) { + if (trapmsg) { + return ngx_proxy_wasm_result_trap(pwexec, trapmsg, + rets, NGX_WAVM_BAD_USAGE); + } + if (none) { return ngx_proxy_wasm_result_notfound(rets); } @@ -376,9 +432,10 @@ ngx_proxy_wasm_hfuncs_set_buffer(ngx_wavm_instance_t *instance, ngx_wavm_ptr_t *buf_data; ngx_http_wasm_req_ctx_t *rctx; ngx_proxy_wasm_exec_t *pwexec; + ngx_proxy_wasm_ctx_t *pwctx; - rctx = ngx_http_proxy_wasm_get_rctx(instance); pwexec = ngx_proxy_wasm_instance2pwexec(instance); + pwctx = pwexec->parent; offset = args[1].of.i32; max = args[2].of.i32; @@ -400,6 +457,26 @@ ngx_proxy_wasm_hfuncs_set_buffer(ngx_wavm_instance_t *instance, #ifdef NGX_WASM_HTTP case NGX_PROXY_WASM_BUFFER_HTTP_REQUEST_BODY: + + /* check context */ + + switch (pwctx->step) { + case NGX_PROXY_WASM_STEP_REQ_HEADERS: + case NGX_PROXY_WASM_STEP_REQ_BODY: + break; + default: + return ngx_proxy_wasm_result_trap(pwexec, + "can only set request body " + "during \"on_request_body\"", + rets, NGX_WAVM_BAD_USAGE); + } + + /* set */ + + rctx = ngx_http_proxy_wasm_get_rctx(instance); + + ngx_wasm_assert(rctx); + if (offset == 0 && max == 0 && buf_len > 0) { rc = ngx_http_wasm_prepend_req_body(rctx, &s); @@ -407,15 +484,29 @@ ngx_proxy_wasm_hfuncs_set_buffer(ngx_wavm_instance_t *instance, rc = ngx_http_wasm_set_req_body(rctx, &s, offset, max); } - if (rc == NGX_ABORT) { + ngx_wasm_assert(rc != NGX_ABORT); + break; + + case NGX_PROXY_WASM_BUFFER_HTTP_RESPONSE_BODY: + + /* check context */ + + switch (pwctx->step) { + case NGX_PROXY_WASM_STEP_RESP_BODY: + break; + default: return ngx_proxy_wasm_result_trap(pwexec, - "cannot set request body", + "can only set response body " + "during \"on_response_body\"", rets, NGX_WAVM_BAD_USAGE); } - break; + /* set */ + + rctx = ngx_http_proxy_wasm_get_rctx(instance); + + ngx_wasm_assert(rctx); - case NGX_PROXY_WASM_BUFFER_HTTP_RESPONSE_BODY: if (offset == 0 && max == 0 && buf_len > 0) { rc = ngx_http_wasm_prepend_resp_body(rctx, &s); @@ -423,12 +514,7 @@ ngx_proxy_wasm_hfuncs_set_buffer(ngx_wavm_instance_t *instance, rc = ngx_http_wasm_set_resp_body(rctx, &s, offset, max); } - if (rc == NGX_ABORT) { - return ngx_proxy_wasm_result_trap(pwexec, - "cannot set response body", - rets, NGX_WAVM_BAD_USAGE); - } - + ngx_wasm_assert(rc != NGX_ABORT); break; #endif @@ -972,12 +1058,33 @@ ngx_proxy_wasm_hfuncs_dispatch_http_call(ngx_wavm_instance_t *instance, uint32_t *callout_id, timeout; ngx_str_t host, body; ngx_proxy_wasm_marshalled_map_t headers, trailers; + ngx_proxy_wasm_ctx_t *pwctx; ngx_proxy_wasm_exec_t *pwexec; ngx_http_wasm_req_ctx_t *rctx; ngx_http_proxy_wasm_dispatch_t *call = NULL; pwexec = ngx_proxy_wasm_instance2pwexec(instance); rctx = ngx_http_proxy_wasm_get_rctx(instance); + pwctx = pwexec->parent; + + /* check context */ + + switch (pwctx->step) { + case NGX_PROXY_WASM_STEP_REQ_HEADERS: + case NGX_PROXY_WASM_STEP_REQ_BODY: + case NGX_PROXY_WASM_STEP_TICK: + case NGX_PROXY_WASM_STEP_DISPATCH_RESPONSE: + break; + default: + return ngx_proxy_wasm_result_trap(pwexec, + "can only send HTTP dispatch " + "during " + "\"on_request_headers\", " + "\"on_request_body\", " + "\"on_dispatch_response\", " + "\"on_tick\"", + rets, NGX_WAVM_BAD_USAGE); + } host.len = args[1].of.i32; host.data = NGX_WAVM_HOST_LIFT_SLICE(instance, args[0].of.i32, host.len); diff --git a/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c b/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c index 6b5c37243..38391e9b1 100644 --- a/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c +++ b/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c @@ -155,7 +155,6 @@ ngx_http_proxy_wasm_dispatch(ngx_proxy_wasm_exec_t *pwexec, /* rctx or fake request */ if (rctx == NULL) { - ngx_wasm_assert(pwexec->in_tick); ngx_wasm_assert(pwexec->root_id == NGX_PROXY_WASM_ROOT_CTX_ID); ngx_wasm_assert(pwexec->parent->id == NGX_PROXY_WASM_ROOT_CTX_ID); @@ -426,6 +425,8 @@ ngx_http_proxy_wasm_dispatch_destroy(ngx_http_proxy_wasm_dispatch_t *call) sock = &call->sock; rctx = call->rctx; + dd("enter"); + ngx_wasm_socket_tcp_destroy(sock); if (call->host.data) { @@ -825,6 +826,11 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) /* save step */ step = pwexec->parent->step; +#ifdef NGX_WASM_HTTP + pwexec->parent->phase = ngx_wasm_phase_lookup(&ngx_http_wasm_subsystem, + NGX_WASM_BACKGROUND_PHASE); +#endif + ecode = ngx_proxy_wasm_run_step(pwexec, NGX_PROXY_WASM_STEP_DISPATCH_RESPONSE); if (ecode != NGX_PROXY_WASM_ERR_NONE) { @@ -838,6 +844,9 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) /* resume current step if unfinished */ rc = ngx_proxy_wasm_resume(pwexec->parent, pwexec->parent->phase, step); + if (rc != NGX_OK && rc != NGX_AGAIN) { + goto error; + } } else { /* another call was setup during the callback */ diff --git a/t/01-wasm/002-shm_queue_sanity.t b/t/01-wasm/002-shm_queue_sanity.t index 7182f48ed..0acedb318 100644 --- a/t/01-wasm/002-shm_queue_sanity.t +++ b/t/01-wasm/002-shm_queue_sanity.t @@ -6,7 +6,7 @@ use t::TestWasm; workers(2); master_on(); -skip_valgrind(); +#skip_valgrind(); plan tests => repeat_each() * (blocks() * 5); diff --git a/t/01-wasm/003-shm_kv_sanity.t b/t/01-wasm/003-shm_kv_sanity.t index 19c7600e6..d890d6479 100644 --- a/t/01-wasm/003-shm_kv_sanity.t +++ b/t/01-wasm/003-shm_kv_sanity.t @@ -6,7 +6,7 @@ use t::TestWasm; workers(2); master_on(); -skip_valgrind(); +#skip_valgrind(); plan tests => repeat_each() * (blocks() * 5); diff --git a/t/01-wasm/directives/001-module_directive.t b/t/01-wasm/directives/001-module_directive.t index 0946d01f2..15bafdb71 100644 --- a/t/01-wasm/directives/001-module_directive.t +++ b/t/01-wasm/directives/001-module_directive.t @@ -8,13 +8,12 @@ our $nginxV = $t::TestWasm::nginxV; plan tests => repeat_each() * (blocks() * 4); +no_shuffle(); run_tests(); __DATA__ === TEST 1: module directive - valid .wasm module -Too slow for Valgrind ---- skip_valgrind: 4 --- main_config eval qq{ wasm { @@ -67,6 +66,7 @@ qr/\[debug\] .*? wasm loading "b" module bytes from ".*?a\.wat"/] === TEST 4: module directive - invalid arguments +--- skip_valgrind: 4 --- main_config wasm { module $TEST_NGINX_HTML_DIR/a.wat; @@ -81,6 +81,7 @@ qr/\[emerg\] .*? invalid number of arguments in "module" directive/ === TEST 5: module directive - bad name +--- skip_valgrind: 4 --- main_config wasm { module '' $TEST_NGINX_HTML_DIR/a.wat; @@ -95,6 +96,7 @@ qr/\[emerg\] .*? invalid module name ""/ === TEST 6: module directive - bad path +--- skip_valgrind: 4 --- main_config wasm { module a ''; @@ -109,6 +111,7 @@ qr/\[emerg\] .*? invalid module path ""/ === TEST 7: module directive - already defined +--- skip_valgrind: 4 --- main_config wasm { module a $TEST_NGINX_HTML_DIR/a.wat; @@ -127,6 +130,7 @@ qr/\[emerg\] .*? "a" module already defined/ === TEST 8: module directive - no such path +--- skip_valgrind: 4 --- main_config wasm { module a $TEST_NGINX_HTML_DIR/none.wat; @@ -141,6 +145,7 @@ qr/\[emerg\] .*? \[wasm\] open\(\) ".*?none\.wat" failed \(2: No such file or di === TEST 9: module directive - no .wat bytes - wasmtime, wasmer +--- skip_valgrind: 4 --- skip_eval: 4: !( $::nginxV =~ m/wasmtime/ || $::nginxV =~ m/wasmer/ ) --- main_config wasm { @@ -160,6 +165,7 @@ qr/\[emerg\] .*? \[wasm\] open\(\) ".*?none\.wat" failed \(2: No such file or di === TEST 10: module directive - no .wat bytes - v8 +--- skip_valgrind: 4 --- skip_eval: 4: $::nginxV !~ m/v8/ --- main_config wasm { @@ -179,6 +185,7 @@ qr/\[emerg\] .*? \[wasm\] open\(\) ".*?none\.wat" failed \(2: No such file or di === TEST 11: module directive - no .wasm bytes +--- skip_valgrind: 4 --- main_config wasm { module a $TEST_NGINX_HTML_DIR/a.wasm; @@ -197,6 +204,7 @@ qr/\[emerg\] .*? \[wasm\] open\(\) ".*?none\.wat" failed \(2: No such file or di === TEST 12: module directive - invalid .wat module - wasmtime, wasmer +--- skip_valgrind: 4 --- skip_eval: 4: !( $::nginxV =~ m/wasmtime/ || $::nginxV =~ m/wasmer/ ) --- main_config wasm { @@ -219,6 +227,7 @@ qr/\[emerg\] .*? \[wasm\] open\(\) ".*?none\.wat" failed \(2: No such file or di === TEST 13: module directive - invalid .wat module - v8 +--- skip_valgrind: 4 --- skip_eval: 4: $::nginxV !~ m/v8/ --- main_config wasm { diff --git a/t/01-wasm/directives/002-compiler_directive.t b/t/01-wasm/directives/002-compiler_directive.t index dfffff79e..ad0fe43a2 100644 --- a/t/01-wasm/directives/002-compiler_directive.t +++ b/t/01-wasm/directives/002-compiler_directive.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); +skip_valgrind('always'); our $nginxV = $t::TestWasm::nginxV; diff --git a/t/01-wasm/directives/003-shm_directives.t b/t/01-wasm/directives/003-shm_directives.t index 2ac92e75e..9563034e6 100644 --- a/t/01-wasm/directives/003-shm_directives.t +++ b/t/01-wasm/directives/003-shm_directives.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); +#skip_valgrind('always'); plan tests => repeat_each() * (blocks() * 5); diff --git a/t/01-wasm/directives/004-resolver_directive.t b/t/01-wasm/directives/004-resolver_directive.t index 041540592..c367f8dc8 100644 --- a/t/01-wasm/directives/004-resolver_directive.t +++ b/t/01-wasm/directives/004-resolver_directive.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); +#skip_valgrind(); plan tests => repeat_each() * (blocks() * 4); diff --git a/t/01-wasm/directives/005-socket_directives.t b/t/01-wasm/directives/005-socket_directives.t index 9376ad4c0..dd42fbaf4 100644 --- a/t/01-wasm/directives/005-socket_directives.t +++ b/t/01-wasm/directives/005-socket_directives.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); +#skip_valgrind(); plan tests => repeat_each() * (blocks() * 4); diff --git a/t/01-wasm/directives/006-backtraces_directive.t b/t/01-wasm/directives/006-backtraces_directive.t index 9fa2a6cb7..40c63135b 100644 --- a/t/01-wasm/directives/006-backtraces_directive.t +++ b/t/01-wasm/directives/006-backtraces_directive.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind('wasmtime'); +#skip_valgrind('wasmtime'); our $nginxV = $t::TestWasm::nginxV; diff --git a/t/01-wasm/directives/008-flag_directive_wasmtime.t b/t/01-wasm/directives/008-flag_directive_wasmtime.t index 89c4259bb..8af43951c 100644 --- a/t/01-wasm/directives/008-flag_directive_wasmtime.t +++ b/t/01-wasm/directives/008-flag_directive_wasmtime.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); +skip_valgrind('always'); our $nginxV = $t::TestWasm::nginxV; our $osname = $t::TestWasm::osname; diff --git a/t/01-wasm/directives/009-flag_directive_wasmer.t b/t/01-wasm/directives/009-flag_directive_wasmer.t index f393152f6..c9a4d5c8f 100644 --- a/t/01-wasm/directives/009-flag_directive_wasmer.t +++ b/t/01-wasm/directives/009-flag_directive_wasmer.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); +skip_valgrind('always'); our $nginxV = $t::TestWasm::nginxV; diff --git a/t/01-wasm/directives/010-flag_directive_v8.t b/t/01-wasm/directives/010-flag_directive_v8.t index 8659bd001..ae0ef8830 100644 --- a/t/01-wasm/directives/010-flag_directive_v8.t +++ b/t/01-wasm/directives/010-flag_directive_v8.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); +skip_valgrind('always'); our $nginxV = $t::TestWasm::nginxV; diff --git a/t/01-wasm/hfuncs/001-log.t b/t/01-wasm/hfuncs/001-log.t index 5ead7563a..3e3b21e14 100644 --- a/t/01-wasm/hfuncs/001-log.t +++ b/t/01-wasm/hfuncs/001-log.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); +skip_valgrind('always'); plan tests => repeat_each() * (blocks() * 3); diff --git a/t/02-http/002-wasm_oob.t b/t/02-http/002-wasm_oob.t index cc5a5b2f8..7ab536933 100644 --- a/t/02-http/002-wasm_oob.t +++ b/t/02-http/002-wasm_oob.t @@ -4,8 +4,6 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); - plan tests => repeat_each() * (blocks() * 4); run_tests(); @@ -13,6 +11,7 @@ run_tests(); __DATA__ === TEST 1: wasm - oob memory read +--- skip_valgrind: 4 --- main_config wasm { module a $TEST_NGINX_HTML_DIR/a.wat; @@ -41,6 +40,7 @@ qr/(\[error\] .*? out of bounds|wasm trap: out of bounds memory access|Uncaught === TEST 2: wasm - oob memory write +--- skip_valgrind: 4 --- main_config wasm { module a $TEST_NGINX_HTML_DIR/a.wat; diff --git a/t/03-proxy_wasm/002-on_root_phases_failures.t b/t/03-proxy_wasm/002-on_root_phases_failures.t index 2b5b5ac9c..dc6ac7ecb 100644 --- a/t/03-proxy_wasm/002-on_root_phases_failures.t +++ b/t/03-proxy_wasm/002-on_root_phases_failures.t @@ -6,8 +6,7 @@ use t::TestWasm; skip_valgrind('wasmtime'); -my $n = 4; -plan tests => repeat_each() * (blocks() * $n); +plan tests => repeat_each() * (blocks() * 4); run_tests(); @@ -17,7 +16,7 @@ __DATA__ 'daemon off' must be set to check exit_code is 2 Valgrind mode already writes 'daemon off' HUP mode does not catch the worker exit_code ---- skip_eval: $n: $ENV{TEST_NGINX_USE_HUP} == 1 +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 --- main_config eval qq{ wasm { @@ -43,7 +42,7 @@ qq{ 'daemon off' must be set to check exit_code is 2 Valgrind mode already writes 'daemon off' HUP mode does not catch the worker exit_code ---- skip_eval: $n: $ENV{TEST_NGINX_USE_HUP} == 1 +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 --- main_config eval qq{ wasm { @@ -70,7 +69,7 @@ qq{ 'daemon off' must be set to check exit_code is 2 Valgrind mode already writes 'daemon off' HUP mode does not catch the worker exit_code ---- skip_eval: $n: $ENV{TEST_NGINX_USE_HUP} == 1 +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 --- main_config eval qq{ wasm { @@ -96,7 +95,7 @@ qq{ 'daemon off' must be set to check exit_code is 2 Valgrind mode already writes 'daemon off' HUP mode does not catch the worker exit_code ---- skip_eval: $n: $ENV{TEST_NGINX_USE_HUP} == 1 +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 --- main_config eval qq{ wasm { diff --git a/t/03-proxy_wasm/hfuncs/100-proxy_log.t b/t/03-proxy_wasm/hfuncs/100-proxy_log.t index ac6ef8c27..dc78ad99e 100644 --- a/t/03-proxy_wasm/hfuncs/100-proxy_log.t +++ b/t/03-proxy_wasm/hfuncs/100-proxy_log.t @@ -36,50 +36,7 @@ ok -=== TEST 2: proxy_wasm - proxy_log() x on_phases ---- load_nginx_modules: ngx_http_echo_module ---- wasm_modules: hostcalls ---- config - location /t/A { - proxy_wasm hostcalls 'on=request_headers \ - test=/t/log/levels'; - echo A; - } - - location /t/B { - proxy_wasm hostcalls 'on=response_headers \ - test=/t/log/levels'; - echo B; - } - - location /t { - proxy_wasm hostcalls 'on=log \ - test=/t/log/levels'; - echo_location /t/A; - echo_location /t/B; - echo C; - } ---- request -GET /t ---- response_body -A -B -C ---- error_log eval -[ - qr/testing in "RequestHeaders"/, - qr/\[error\] .*? proxy_log error/, - qr/testing in "ResponseHeaders"/, - qr/\[error\] .*? proxy_log error/, - qr/testing in "Log"/, - qr/\[error\] .*? proxy_log error/, -] ---- no_error_log -[alert] - - - -=== TEST 3: proxy_wasm - proxy_log() bad log level +=== TEST 2: proxy_wasm - proxy_log() bad log level --- load_nginx_modules: ngx_http_echo_module --- wasm_modules: hostcalls --- config diff --git a/t/03-proxy_wasm/hfuncs/101-proxy_get_current_time.t b/t/03-proxy_wasm/hfuncs/101-proxy_get_current_time.t index e2c310970..45dde40a0 100644 --- a/t/03-proxy_wasm/hfuncs/101-proxy_get_current_time.t +++ b/t/03-proxy_wasm/hfuncs/101-proxy_get_current_time.t @@ -24,8 +24,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: 2.*? UTC/, --- no_error_log [error] diff --git a/t/03-proxy_wasm/hfuncs/106-proxy_get_http_response_header.t b/t/03-proxy_wasm/hfuncs/106-proxy_get_http_response_header.t index 36c8ba5c8..8b5496ec8 100644 --- a/t/03-proxy_wasm/hfuncs/106-proxy_get_http_response_header.t +++ b/t/03-proxy_wasm/hfuncs/106-proxy_get_http_response_header.t @@ -301,6 +301,7 @@ resp header "connection: close".*/ === TEST 10: proxy_wasm - get_http_response_header() get Connection header (keep-alive) +--- skip_valgrind: 5 --- timeout_expected: 5 --- abort --- load_nginx_modules: ngx_http_echo_module @@ -379,6 +380,7 @@ resp header "connection: upgrade".*/ === TEST 12: proxy_wasm - get_http_response_header() get Keep-Alive header +--- skip_valgrind: 5 --- timeout_expected: 5 --- abort --- load_nginx_modules: ngx_http_echo_module diff --git a/t/03-proxy_wasm/hfuncs/111-proxy_set_http_request_header.t b/t/03-proxy_wasm/hfuncs/111-proxy_set_http_request_header.t index 8c7a05bb5..8521ece21 100644 --- a/t/03-proxy_wasm/hfuncs/111-proxy_set_http_request_header.t +++ b/t/03-proxy_wasm/hfuncs/111-proxy_set_http_request_header.t @@ -160,6 +160,7 @@ qr/.*? on_request_headers, 22 headers.* === TEST 7: proxy_wasm - set_http_request_header() sets Connection header (keep-alive) +--- skip_valgrind: 5 --- timeout_expected: 5 --- abort --- wasm_modules: hostcalls diff --git a/t/03-proxy_wasm/hfuncs/112-proxy_set_http_response_header.t b/t/03-proxy_wasm/hfuncs/112-proxy_set_http_response_header.t index 37d107ab7..23ac5f603 100644 --- a/t/03-proxy_wasm/hfuncs/112-proxy_set_http_response_header.t +++ b/t/03-proxy_wasm/hfuncs/112-proxy_set_http_response_header.t @@ -199,6 +199,7 @@ resp Connection: upgrade.*/ === TEST 8: proxy_wasm - set_http_response_header() sets Connection header (keep-alive) +--- skip_valgrind: 5 --- timeout_expected: 5 --- abort --- wasm_modules: hostcalls diff --git a/t/03-proxy_wasm/hfuncs/114-proxy_set_http_request_body.t b/t/03-proxy_wasm/hfuncs/114-proxy_set_http_request_body.t index 1c31f21b1..310dbf035 100644 --- a/t/03-proxy_wasm/hfuncs/114-proxy_set_http_request_body.t +++ b/t/03-proxy_wasm/hfuncs/114-proxy_set_http_request_body.t @@ -204,61 +204,3 @@ HelloWorld [error] [crit] [alert] - - - -=== TEST 7: proxy_wasm - set_http_request_body() x on_phases ---- load_nginx_modules: ngx_http_echo_module ---- wasm_modules: hostcalls ---- config - location /request_headers { - # ok - proxy_wasm hostcalls 'on=request_headers \ - test=/t/set_request_body \ - value=from_request_headers'; - echo $request_body; - } - - location /request_body { - # ok - proxy_wasm hostcalls 'on=request_body \ - test=/t/set_request_body \ - value=from_request_body'; - echo $request_body; - } - - location /response_headers { - # cannot set request body - proxy_wasm hostcalls 'on=response_headers \ - test=/t/set_request_body'; - echo $request_body; - } - - location /log { - # not executed (subrequest) - proxy_wasm hostcalls 'on=log \ - test=/t/set_request_body'; - echo $request_body; - } - - location /t { - echo_subrequest POST /request_headers -b 'orig'; - echo_subrequest POST /request_body -b 'orig'; - echo_subrequest POST /response_headers -b 'orig'; - echo_subrequest POST /log -b 'orig'; - - # cannot resume - proxy_wasm hostcalls 'on=response_body test=/t/log/request_body'; - } ---- response_body eval -qr/from_request_headers -from_request_body -[\s\S]+500 Internal Server Error/ ---- grep_error_log eval: qr/(.*?cannot set|\[.*?failed resuming).*/ ---- grep_error_log_out eval -qr/.*?host trap \(bad usage\): cannot set request body.* -\[info\] .*? \*\d+ .*? filter chain failed resuming: previous error \(instance trapped\).*? subrequest: "\/response_headers".* -\z/ ---- no_error_log -[alert] -[stderr] diff --git a/t/03-proxy_wasm/hfuncs/116-proxy_set_http_response_body.t b/t/03-proxy_wasm/hfuncs/116-proxy_set_http_response_body.t index 15ce88076..8d07b69c4 100644 --- a/t/03-proxy_wasm/hfuncs/116-proxy_set_http_response_body.t +++ b/t/03-proxy_wasm/hfuncs/116-proxy_set_http_response_body.t @@ -133,7 +133,7 @@ on_response_body, 0 bytes, eof: true.*/ location /t { echo_subrequest GET /subrequest; - proxy_wasm hostcalls 'on=response_headers \ + proxy_wasm hostcalls 'on=log \ test=/t/log/response_body'; } --- response_headers @@ -305,52 +305,3 @@ on_response_body, 0 bytes, eof: true.*/ --- no_error_log [error] [crit] - - - -=== TEST 7: proxy_wasm - set_http_response_body() x on_phases -should not be usable anywhere else than on_http_response_body -should not be retrievable after on_http_response_body since buffers are consumed ---- load_nginx_modules: ngx_http_echo_module ---- wasm_modules: hostcalls ---- config - proxy_wasm_isolation filter; - - location /request_headers { - internal; - echo; - proxy_wasm hostcalls 'on=request_headers \ - test=/t/set_response_body'; - proxy_wasm hostcalls 'on=request_headers \ - test=/t/log/response_body'; - } - - location /response_headers { - internal; - echo; - proxy_wasm hostcalls 'on=response_headers \ - test=/t/set_response_body'; - proxy_wasm hostcalls 'on=response_headers \ - test=/t/log/response_body'; - } - - location /t { - echo_subrequest GET /request_headers; - echo_subrequest GET /response_headers; - proxy_wasm hostcalls 'on=log test=/t/set_response_body'; - } ---- response_headers -Transfer-Encoding: chunked -Content-Length: ---- response_body eval -qr/500 Internal Server Error/ ---- grep_error_log eval: qr/(.*?cannot set|\[.*?failed resuming).*/ ---- grep_error_log_out eval -qr/.*?host trap \(bad usage\): cannot set response body.* -\[info\] .*? \*\d+ .*? filter chain failed resuming: previous error \(instance trapped\).*? subrequest: "\/request_headers".* -.*?host trap \(bad usage\): cannot set response body.* -\[info\] .*? \*\d+ .*? filter chain failed resuming: previous error \(instance trapped\).*? subrequest: "\/response_headers".* -.*?host trap \(bad usage\): cannot set response body.*/ ---- no_error_log -[alert] -[stderr] diff --git a/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t b/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t index bf0c0772f..777634248 100644 --- a/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t +++ b/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t @@ -1171,31 +1171,7 @@ qr/^\*\d+ .*? on_http_call_response \(id: \d+[^*]* -=== TEST 46: proxy_wasm - dispatch_http_call() on log step ---- load_nginx_modules: ngx_http_echo_module ---- wasm_modules: hostcalls ---- config - location /dispatched { - return 200 "Hello world"; - } - - location /t { - proxy_wasm hostcalls 'on=log \ - test=/t/dispatch_http_call \ - host=127.0.0.1:$TEST_NGINX_SERVER_PORT \ - path=/dispatched'; - echo fail; - } ---- response_body -fail ---- error_log eval -qr/(\[error\]|Uncaught RuntimeError|\s+).*?dispatch failed: bad step/ ---- no_error_log -[crit] - - - -=== TEST 47: proxy_wasm - dispatch_http_call() supports get_http_call_response_headers() +=== TEST 46: proxy_wasm - dispatch_http_call() supports get_http_call_response_headers() --- load_nginx_modules: ngx_http_echo_module --- wasm_modules: hostcalls --- config @@ -1219,7 +1195,7 @@ X-Callout-Header: callout-header-value -=== TEST 48: proxy_wasm - dispatch_http_call() get :status dispatch response header +=== TEST 47: proxy_wasm - dispatch_http_call() get :status dispatch response header --- load_nginx_modules: ngx_http_echo_module --- wasm_modules: hostcalls --- config @@ -1262,7 +1238,7 @@ qr/^\*\d+ .*? on_http_call_response \(id: \d+, status: 200[^*]* -=== TEST 49: proxy_wasm - dispatch_http_call() with dispatched request body +=== TEST 48: proxy_wasm - dispatch_http_call() with dispatched request body --- load_nginx_modules: ngx_http_echo_module --- wasm_modules: hostcalls --- config @@ -1288,7 +1264,7 @@ helloworld -=== TEST 50: proxy_wasm - dispatch_http_call() override Content-Length +=== TEST 49: proxy_wasm - dispatch_http_call() override Content-Length --- load_nginx_modules: ngx_http_echo_module --- wasm_modules: hostcalls --- config @@ -1315,7 +1291,7 @@ helloworl -=== TEST 51: proxy_wasm - dispatch_http_call() cannot override hard-coded request headers +=== TEST 50: proxy_wasm - dispatch_http_call() cannot override hard-coded request headers --- skip_no_debug: 4 --- load_nginx_modules: ngx_http_echo_module --- wasm_modules: hostcalls diff --git a/t/03-proxy_wasm/hfuncs/contexts/002-set_tick_period.t b/t/03-proxy_wasm/hfuncs/contexts/002-set_tick_period.t new file mode 100644 index 000000000..b8f213f3e --- /dev/null +++ b/t/03-proxy_wasm/hfuncs/contexts/002-set_tick_period.t @@ -0,0 +1,102 @@ +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: + +use strict; +use lib '.'; +use t::TestWasm; + +skip_hup(); +skip_no_debug(); +skip_valgrind('always'); + +plan tests => repeat_each() * (blocks() * 4); + +run_tests(); + +__DATA__ + +=== TEST 1: proxy_wasm contexts - set_tick_period on_vm_start +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm 'set_tick_period'; + } +--- config + location /t { + proxy_wasm context_checks; + return 200; + } +--- ignore_response_body +--- error_log +set_tick_period status: 0 +--- no_error_log +[error] +[crit] + + + +=== TEST 2: proxy_wasm contexts - set_tick_period on_configure +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_configure=set_tick_period'; + return 200; + } +--- ignore_response_body +--- error_log +set_tick_period status: 0 +--- no_error_log +[error] +[crit] + + + +=== TEST 3: proxy_wasm contexts - set_tick_period on_tick +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_tick=set_tick_period'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +tick_period already set +--- no_error_log +[crit] + + + +=== TEST 4: proxy_wasm contexts - set_tick_period on_http_dispatch_response +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_http_dispatch_response=set_tick_period \ + host=127.0.0.1:$TEST_NGINX_SERVER_PORT'; + return 200; + } + + location /dispatch { + return 200; + } +--- ignore_response_body +--- error_log +can only set tick_period in root context +--- no_error_log +[crit] +[alert] + + + +=== TEST 5: proxy_wasm contexts - set_tick_period on_request_headers +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_request_headers=set_tick_period'; + return 200; + } +--- error_code: 500 +--- ignore_response_body +--- error_log +can only set tick_period in root context +--- no_error_log +[crit] +[alert] diff --git a/t/03-proxy_wasm/hfuncs/contexts/100-proxy_log.t b/t/03-proxy_wasm/hfuncs/contexts/100-proxy_log.t new file mode 100644 index 000000000..dff0ae0f1 --- /dev/null +++ b/t/03-proxy_wasm/hfuncs/contexts/100-proxy_log.t @@ -0,0 +1,191 @@ +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: + +use strict; +use lib '.'; +use t::TestWasm; + +skip_hup(); +skip_no_debug(); +skip_valgrind('always'); + +plan tests => repeat_each() * (blocks() * 4); + +run_tests(); + +__DATA__ + +=== TEST 1: proxy_wasm contexts - proxy_log on_vm_start +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm 'proxy_log'; + } +--- config + location /t { + proxy_wasm context_checks; + return 200; + } +--- ignore_response_body +--- error_log +proxy_log msg +--- no_error_log +[error] +[crit] + + + +=== TEST 2: proxy_wasm contexts - proxy_log on_configure +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm; + } +--- config + location /t { + proxy_wasm context_checks 'on_configure=proxy_log'; + return 200; + } +--- ignore_response_body +--- error_log +proxy_log msg +--- no_error_log +[error] +[crit] + + + +=== TEST 3: proxy_wasm contexts - proxy_log on_tick +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm; + } +--- config + location /t { + proxy_wasm context_checks 'on_tick=proxy_log'; + return 200; + } +--- ignore_response_body +--- error_log +proxy_log msg +--- no_error_log +[error] +[crit] + + + +=== TEST 4: proxy_wasm contexts - proxy_log on_http_dispatch_response +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_http_dispatch_response=proxy_log \ + host=127.0.0.1:$TEST_NGINX_SERVER_PORT'; + return 200; + } + + location /dispatch { + return 200; + } +--- ignore_response_body +--- error_log +proxy_log msg +--- no_error_log +[error] +[crit] + + + +=== TEST 5: proxy_wasm contexts - proxy_log on_request_headers +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm; + } +--- config + location /t { + proxy_wasm context_checks 'on_request_headers=proxy_log'; + return 200; + } +--- ignore_response_body +--- error_log +proxy_log msg +--- no_error_log +[error] +[crit] + + + +=== TEST 6: proxy_wasm contexts - proxy_log on_request_body +--- load_nginx_modules: ngx_http_echo_module +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm; + } +--- config + location /t { + proxy_wasm context_checks 'on_request_body=proxy_log'; + echo ok; + } +--- request +POST /t +payload +--- ignore_response_body +--- error_log +proxy_log msg +--- no_error_log +[error] +[crit] + + + +=== TEST 7: proxy_wasm contexts - proxy_log on_response_headers +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm; + } +--- config + location /t { + proxy_wasm context_checks 'on_response_headers=proxy_log'; + return 200; + } +--- ignore_response_body +--- error_log +proxy_log msg +--- no_error_log +[error] +[crit] + + + +=== TEST 8: proxy_wasm contexts - proxy_log on_response_body +--- load_nginx_modules: ngx_http_echo_module +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm; + } +--- config + location /t { + proxy_wasm context_checks 'on_response_body=proxy_log'; + echo ok; + } +--- ignore_response_body +--- error_log +proxy_log msg +--- no_error_log +[error] +[crit] + + + +=== TEST 9: proxy_wasm contexts - proxy_log on_log +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm; + } +--- config + location /t { + proxy_wasm context_checks 'on_log=proxy_log'; + return 200; + } +--- ignore_response_body +--- error_log +proxy_log msg +--- no_error_log +[error] +[crit] diff --git a/t/03-proxy_wasm/hfuncs/contexts/113-proxy_get_http_request_body.t b/t/03-proxy_wasm/hfuncs/contexts/113-proxy_get_http_request_body.t new file mode 100644 index 000000000..0ff1f540e --- /dev/null +++ b/t/03-proxy_wasm/hfuncs/contexts/113-proxy_get_http_request_body.t @@ -0,0 +1,102 @@ +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: + +use strict; +use lib '.'; +use t::TestWasm; + +skip_hup(); +skip_no_debug(); +skip_valgrind('always'); + +plan tests => repeat_each() * (blocks() * 4); + +run_tests(); + +__DATA__ + +=== TEST 1: proxy_wasm contexts - get_http_request_body on_vm_start +'daemon off' must be set to check exit_code is 2 +Valgrind mode already writes 'daemon off' +HUP mode does not catch the worker exit_code +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 +--- main_config eval +qq{ + wasm { + module context_checks $ENV{TEST_NGINX_CRATES_DIR}/context_checks.wasm 'get_request_body_buffer'; + } +}.($ENV{TEST_NGINX_USE_VALGRIND} ? '' : 'daemon off;') +--- config + location /t { + proxy_wasm context_checks; + return 200; + } +--- ignore_response_body +--- error_log +[error] +[emerg] +can only get request body during "on_request_body", "on_log" +--- no_error_log +--- must_die: 2 + + + +=== TEST 2: proxy_wasm contexts - get_http_request_body on_configure +'daemon off' must be set to check exit_code is 2 +Valgrind mode already writes 'daemon off' +HUP mode does not catch the worker exit_code +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 +--- main_config eval +qq{ + wasm { + module context_checks $ENV{TEST_NGINX_CRATES_DIR}/context_checks.wasm; + } +}.($ENV{TEST_NGINX_USE_VALGRIND} ? '' : 'daemon off;') +--- config + location /t { + proxy_wasm context_checks 'on_configure=get_request_body_buffer'; + return 200; + } + +--- ignore_response_body +--- error_log +[error] +[emerg] +can only get request body during "on_request_body", "on_log" +--- must_die: 2 + + + +=== TEST 3: proxy_wasm contexts - get_http_request_body on_tick +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_tick=get_request_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only get request body during "on_request_body", "on_log" +--- no_error_log +[crit] + + + +=== TEST 4: proxy_wasm contexts - get_http_request_body on_http_dispatch_response +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_http_dispatch_response=get_request_body_buffer \ + host=127.0.0.1:$TEST_NGINX_SERVER_PORT'; + return 200; + } + + location /dispatch { + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only get request body during "on_request_body", "on_log" +--- no_error_log +[crit] diff --git a/t/03-proxy_wasm/hfuncs/contexts/114-proxy_set_http_request_body.t b/t/03-proxy_wasm/hfuncs/contexts/114-proxy_set_http_request_body.t new file mode 100644 index 000000000..f3c7a16bc --- /dev/null +++ b/t/03-proxy_wasm/hfuncs/contexts/114-proxy_set_http_request_body.t @@ -0,0 +1,186 @@ +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: + +use strict; +use lib '.'; +use t::TestWasm; + +skip_hup(); +skip_no_debug(); +skip_valgrind('always'); + +plan tests => repeat_each() * (blocks() * 4); + +run_tests(); + +__DATA__ + +=== TEST 1: proxy_wasm contexts - set_http_request_body on_vm_start +'daemon off' must be set to check exit_code is 2 +Valgrind mode already writes 'daemon off' +HUP mode does not catch the worker exit_code +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 +--- main_config eval +qq{ + wasm { + module context_checks $ENV{TEST_NGINX_CRATES_DIR}/context_checks.wasm 'set_request_body_buffer'; + } +}.($ENV{TEST_NGINX_USE_VALGRIND} ? '' : 'daemon off;') +--- config + location /t { + proxy_wasm context_checks; + return 200; + } +--- ignore_response_body +--- error_log +[error] +[emerg] +can only set request body during "on_request_body" +--- no_error_log +--- must_die: 2 + + + +=== TEST 2: proxy_wasm contexts - set_http_request_body on_configure +'daemon off' must be set to check exit_code is 2 +Valgrind mode already writes 'daemon off' +HUP mode does not catch the worker exit_code +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 +--- main_config eval +qq{ + wasm { + module context_checks $ENV{TEST_NGINX_CRATES_DIR}/context_checks.wasm; + } +}.($ENV{TEST_NGINX_USE_VALGRIND} ? '' : 'daemon off;') +--- config + location /t { + proxy_wasm context_checks 'on_configure=set_request_body_buffer'; + return 200; + } + +--- ignore_response_body +--- error_log +[error] +[emerg] +can only set request body during "on_request_body" +--- must_die: 2 + + + +=== TEST 3: proxy_wasm contexts - set_http_request_body on_tick +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_tick=set_request_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only set request body during "on_request_body" +--- no_error_log +[crit] + + + +=== TEST 4: proxy_wasm contexts - set_http_request_body on_http_dispatch_response +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_http_dispatch_response=set_request_body_buffer \ + host=127.0.0.1:$TEST_NGINX_SERVER_PORT'; + return 200; + } + + location /dispatch { + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only set request body during "on_request_body" +--- no_error_log +[crit] + + + +=== TEST 5: proxy_wasm contexts - set_http_request_body on_request_headers +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_request_headers=set_request_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +set_request_body_buffer status: 0 +--- no_error_log +[error] +[crit] + + + +=== TEST 6: proxy_wasm contexts - set_http_request_body on_request_body +--- load_nginx_modules: ngx_http_echo_module +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_request_body=set_request_body_buffer'; + echo ok; + } +--- request +POST /t +hello +--- ignore_response_body +--- error_log +set_request_body_buffer status: 0 +--- no_error_log +[error] +[crit] + + + +=== TEST 7: proxy_wasm contexts - set_http_request_body on_response_headers +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_response_headers=set_request_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only set request body during "on_request_body" +--- no_error_log +[crit] + + + +=== TEST 8: proxy_wasm contexts - set_http_request_body on_response_body (request_body_buffer) +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_response_body=set_request_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only set request body during "on_request_body" +--- no_error_log +[crit] + + + +=== TEST 9: proxy_wasm contexts - set_http_request_body on_log +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_log=set_request_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only set request body during "on_request_body" +--- no_error_log +[crit] diff --git a/t/03-proxy_wasm/hfuncs/contexts/115-proxy_get_http_response_body.t b/t/03-proxy_wasm/hfuncs/contexts/115-proxy_get_http_response_body.t new file mode 100644 index 000000000..c5bfadaa3 --- /dev/null +++ b/t/03-proxy_wasm/hfuncs/contexts/115-proxy_get_http_response_body.t @@ -0,0 +1,101 @@ +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: + +use strict; +use lib '.'; +use t::TestWasm; + +skip_hup(); +skip_no_debug(); +skip_valgrind('always'); + +plan tests => repeat_each() * (blocks() * 4); + +run_tests(); + +__DATA__ + +=== TEST 1: proxy_wasm contexts - get_http_response_body on_vm_start (response_body_buffer) +'daemon off' must be set to check exit_code is 2 +Valgrind mode already writes 'daemon off' +HUP mode does not catch the worker exit_code +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 +--- main_config eval +qq{ + wasm { + module context_checks $ENV{TEST_NGINX_CRATES_DIR}/context_checks.wasm 'get_response_body_buffer'; + } +}.($ENV{TEST_NGINX_USE_VALGRIND} ? '' : 'daemon off;') +--- config + location /t { + proxy_wasm context_checks; + return 200; + } +--- ignore_response_body +--- error_log +[error] +[emerg] +can only get response body during "on_response_body", "on_log" +--- no_error_log +--- must_die: 2 + + + +=== TEST 2: proxy_wasm contexts - get_http_response_body on_configure +'daemon off' must be set to check exit_code is 2 +Valgrind mode already writes 'daemon off' +HUP mode does not catch the worker exit_code +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 +--- main_config eval +qq{ + wasm { + module context_checks $ENV{TEST_NGINX_CRATES_DIR}/context_checks.wasm; + } +}.($ENV{TEST_NGINX_USE_VALGRIND} ? '' : 'daemon off;') +--- config + location /t { + proxy_wasm context_checks 'on_configure=get_response_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +[emerg] +can only get response body during "on_response_body", "on_log" +--- must_die: 2 + + + +=== TEST 3: proxy_wasm contexts - get_http_response_body on_tick +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_tick=get_response_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only get response body during "on_response_body", "on_log" +--- no_error_log +[crit] + + + +=== TEST 4: proxy_wasm contexts - get_http_response_body on_http_dispatch_response +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_http_dispatch_response=get_response_body_buffer \ + host=127.0.0.1:$TEST_NGINX_SERVER_PORT'; + return 200; + } + + location /dispatch { + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only get response body during "on_response_body", "on_log" +--- no_error_log +[crit] diff --git a/t/03-proxy_wasm/hfuncs/contexts/116-proxy_set_http_response_body.t b/t/03-proxy_wasm/hfuncs/contexts/116-proxy_set_http_response_body.t new file mode 100644 index 000000000..792373a0c --- /dev/null +++ b/t/03-proxy_wasm/hfuncs/contexts/116-proxy_set_http_response_body.t @@ -0,0 +1,189 @@ +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: + +use strict; +use lib '.'; +use t::TestWasm; + +skip_hup(); +skip_no_debug(); +skip_valgrind('always'); + +plan tests => repeat_each() * (blocks() * 4); + +run_tests(); + +__DATA__ + +=== TEST 1: proxy_wasm contexts - set_http_response_body on_vm_start +'daemon off' must be set to check exit_code is 2 +Valgrind mode already writes 'daemon off' +HUP mode does not catch the worker exit_code +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 +--- main_config eval +qq{ + wasm { + module context_checks $ENV{TEST_NGINX_CRATES_DIR}/context_checks.wasm 'set_response_body_buffer'; + } +}.($ENV{TEST_NGINX_USE_VALGRIND} ? '' : 'daemon off;') +--- config + location /t { + proxy_wasm context_checks; + return 200; + } +--- ignore_response_body +--- error_log +[error] +[emerg] +can only set response body during "on_response_body" +--- no_error_log +--- must_die: 2 + + + +=== TEST 2: proxy_wasm contexts - set_http_response_body on_configure +'daemon off' must be set to check exit_code is 2 +Valgrind mode already writes 'daemon off' +HUP mode does not catch the worker exit_code +--- skip_eval: 4: $ENV{TEST_NGINX_USE_HUP} == 1 +--- main_config eval +qq{ + wasm { + module context_checks $ENV{TEST_NGINX_CRATES_DIR}/context_checks.wasm; + } +}.($ENV{TEST_NGINX_USE_VALGRIND} ? '' : 'daemon off;') +--- config + location /t { + proxy_wasm context_checks 'on_configure=set_response_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +[emerg] +can only set response body during "on_response_body" +--- must_die: 2 + + + +=== TEST 3: proxy_wasm contexts - set_http_response_body on_tick +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_tick=set_response_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only set response body during "on_response_body" +--- no_error_log +[crit] + + + +=== TEST 4: proxy_wasm contexts - set_http_response_body on_http_dispatch_response +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_http_dispatch_response=set_response_body_buffer \ + host=127.0.0.1:$TEST_NGINX_SERVER_PORT'; + return 200; + } + + location /dispatch { + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only set response body during "on_response_body" +--- no_error_log +[crit] + + + +=== TEST 5: proxy_wasm contexts - set_http_response_body on_request_headers +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_request_headers=set_response_body_buffer'; + return 200; + } +--- error_code: 500 +--- ignore_response_body +--- error_log +[error] +can only set response body during "on_response_body" +--- no_error_log +[crit] + + + +=== TEST 6: proxy_wasm contexts - set_http_response_body on_request_body +--- load_nginx_modules: ngx_http_echo_module +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_request_body=set_response_body_buffer'; + echo ok; + } +--- request +POST /t +hello +--- error_code: 500 +--- ignore_response_body +--- error_log +[error] +can only set response body during "on_response_body" +--- no_error_log +[crit] + + + +=== TEST 7: proxy_wasm contexts - set_http_response_body on_response_headers +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_response_headers=set_response_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only set response body during "on_response_body" +--- no_error_log +[crit] + + + +=== TEST 8: proxy_wasm contexts - set_http_response_body on_response_body +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_response_body=set_response_body_buffer'; + return 200; + } +--- error_code: +--- ignore_response_body +--- error_log +set_response_body_buffer status: 0 +--- no_error_log +[error] +[crit] + + + +=== TEST 9: proxy_wasm contexts - set_http_response_body on_log +should not be retrievable after on_response_body since buffers are consumed +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_log=set_response_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only set response body during "on_response_body" +--- no_error_log +[crit] diff --git a/t/03-proxy_wasm/hfuncs/contexts/130-proxy_dispatch_http.t b/t/03-proxy_wasm/hfuncs/contexts/130-proxy_dispatch_http.t new file mode 100644 index 000000000..65469b03d --- /dev/null +++ b/t/03-proxy_wasm/hfuncs/contexts/130-proxy_dispatch_http.t @@ -0,0 +1,78 @@ +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: + +use strict; +use lib '.'; +use t::TestWasm; + +skip_hup(); +skip_no_debug(); +skip_valgrind('always'); + +plan tests => repeat_each() * (blocks() * 4); + +run_tests(); + +__DATA__ + +=== TEST 1: proxy_wasm contexts - dispatch_http_call on_vm_start +--- main_config + wasm { + module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm 'dispatch_http_call'; + } +--- config + location /t { + proxy_wasm context_checks; + return 200; + } +--- must_die: 0 +--- error_log +[error] +can only send HTTP dispatch during "on_request_headers", "on_request_body", "on_dispatch_response", "on_tick" +--- no_error_log +[crit] + + + +=== TEST 2: proxy_wasm contexts - dispatch_http_call on_configure +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_configure=dispatch_http_call'; + return 200; + } +--- must_die: 0 +--- error_log +[error] +can only send HTTP dispatch during "on_request_headers", "on_request_body", "on_dispatch_response", "on_tick" +--- no_error_log +[crit] + + + +=== TEST 3: proxy_wasm contexts - dispatch_http_call on_tick +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_tick=dispatch_http_call'; + return 200; + } +--- error_log +dispatch failed: no :method +--- no_error_log +[crit] +[emerg] + + + +=== TEST 4: proxy_wasm contexts - dispatch_http_call on_log +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_log=dispatch_http_call'; + return 200; + } +--- error_log +[error] +can only send HTTP dispatch during "on_request_headers", "on_request_body", "on_dispatch_response", "on_tick" +--- no_error_log +[crit] diff --git a/t/03-proxy_wasm/hfuncs/contexts/131-proxy_get_http_dispatch_response_body.t b/t/03-proxy_wasm/hfuncs/contexts/131-proxy_get_http_dispatch_response_body.t new file mode 100644 index 000000000..05efb5d5d --- /dev/null +++ b/t/03-proxy_wasm/hfuncs/contexts/131-proxy_get_http_dispatch_response_body.t @@ -0,0 +1,29 @@ +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: + +use strict; +use lib '.'; +use t::TestWasm; + +skip_hup(); +skip_no_debug(); +skip_valgrind('always'); + +plan tests => repeat_each() * (blocks() * 4); + +run_tests(); + +__DATA__ + +=== TEST 1: proxy_wasm contexts - get_http_dispatch_response_body on_tick +--- wasm_modules: context_checks +--- config + location /t { + proxy_wasm context_checks 'on_tick=get_dispatch_response_body_buffer'; + return 200; + } +--- ignore_response_body +--- error_log +[error] +can only get dispatch response body during "on_http_dispatch_response" +--- no_error_log +[crit] diff --git a/t/04-openresty/ffi/200-proxy_wasm_and_lua_sanity.t b/t/04-openresty/ffi/200-proxy_wasm_and_lua_sanity.t index 161bbed3c..60a18aaf4 100644 --- a/t/04-openresty/ffi/200-proxy_wasm_and_lua_sanity.t +++ b/t/04-openresty/ffi/200-proxy_wasm_and_lua_sanity.t @@ -245,7 +245,7 @@ qr/on_http_call_response \(id: \d+, status: 200, headers: 5, body_bytes: \d+, tr --- grep_error_log eval: qr/\*\d+.*?\[proxy-wasm\].*?(resuming|freeing).*/ --- grep_error_log_out eval qr/\A\*\d+ .*? filter 1\/1 resuming "on_request_headers" step in "rewrite" phase[^#*]* -\*\d+ .*? filter 1\/1 resuming "on_dispatch_response" step in "access" phase[^#*]* +\*\d+ .*? filter 1\/1 resuming "on_dispatch_response" step in "background" phase[^#*]* \*\d+ .*? filter 1\/1 resuming "on_response_headers" step in "header_filter" phase[^#*]* \*\d+ .*? filter 1\/1 resuming "on_response_body" step in "body_filter" phase[^#*]* \*\d+ .*? filter 1\/1 resuming "on_log" step in "log" phase[^#*]* @@ -308,7 +308,7 @@ qr/on_http_call_response \(id: \d+, status: 200, headers: 5, body_bytes: \d+, tr --- grep_error_log eval: qr/\*\d+.*?\[proxy-wasm\].*?(resuming|freeing).*/ --- grep_error_log_out eval qr/\A\*\d+ .*? filter 1\/1 resuming "on_request_headers" step in "rewrite" phase[^#*]* -\*\d+ .*? filter 1\/1 resuming "on_dispatch_response" step in "access" phase[^#*]* +\*\d+ .*? filter 1\/1 resuming "on_dispatch_response" step in "background" phase[^#*]* \*\d+ .*? filter 1\/1 resuming "on_response_headers" step in "header_filter" phase[^#*]* \*\d+ .*? filter 1\/1 resuming "on_response_body" step in "body_filter" phase[^#*]* \*\d+ .*? filter 1\/1 resuming "on_response_body" step in "body_filter" phase[^#*]* @@ -377,7 +377,7 @@ qr/\A\*\d+ .*? filter 1\/1 resuming "on_request_headers" step in "rewrite" phase --- grep_error_log eval: qr/\*\d+.*?\[proxy-wasm\].*?(resuming|freeing).*/ --- grep_error_log_out eval qr/\A\*\d+ .*? filter 1\/1 resuming "on_request_headers" step in "rewrite" phase[^#*]* -\*\d+ .*? filter 1\/1 resuming "on_dispatch_response" step in "access" phase[^#*]* +\*\d+ .*? filter 1\/1 resuming "on_dispatch_response" step in "background" phase[^#*]* \*\d+ .*? filter chain failed resuming: previous error \(dispatch failure\)[^#*]* \*\d+ .*? filter freeing context #\d+ \(1\/1\)[^#*]*\Z/ diff --git a/t/05-others/002-resolver_add_sanity.t b/t/05-others/002-resolver_add_sanity.t index d4dc7e4ef..df7417bf8 100644 --- a/t/05-others/002-resolver_add_sanity.t +++ b/t/05-others/002-resolver_add_sanity.t @@ -4,7 +4,7 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind('wasmtime'); +#skip_valgrind('wasmtime'); plan tests => repeat_each() * (blocks() * 4); diff --git a/t/05-others/010-client_connection_abort.t b/t/05-others/010-client_connection_abort.t index d49637f5a..71111b674 100644 --- a/t/05-others/010-client_connection_abort.t +++ b/t/05-others/010-client_connection_abort.t @@ -4,12 +4,9 @@ use strict; use lib '.'; use t::TestWasm; -if ($ENV{TEST_NGINX_USE_HUP}) { - plan(skip_all => "unavailable in HUP mode"); +skip_hup(); -} else { - plan tests => repeat_each() * (blocks() * 4); -} +plan tests => repeat_each() * (blocks() * 4); run_tests(); diff --git a/t/05-others/011-upstream_connection_abort.t b/t/05-others/011-upstream_connection_abort.t index 86703b0c7..ae07a178a 100644 --- a/t/05-others/011-upstream_connection_abort.t +++ b/t/05-others/011-upstream_connection_abort.t @@ -4,14 +4,9 @@ use strict; use lib '.'; use t::TestWasm; -skip_valgrind(); +skip_hup(); -if ($ENV{TEST_NGINX_USE_HUP}) { - plan(skip_all => "unavailable in HUP mode"); - -} else { - plan tests => repeat_each() * (blocks() * 4); -} +plan tests => repeat_each() * (blocks() * 4); run_tests(); @@ -19,7 +14,7 @@ __DATA__ === TEST 1: upstream connection abort - wasm_call Calls on aborted upstream connections execute response phases on the produced -HTTP 502 response. +--- skip_valgrind: 4 --- skip_no_debug: 4 --- wasm_modules: ngx_rust_tests --- tcp_listen: $TEST_NGINX_UNIX_SOCKET @@ -54,6 +49,7 @@ wasm ops calling "ngx_rust_tests\.log_notice_hello" in "body_filter" phase\Z/ === TEST 2: upstream connection abort - chained filters Filters on aborted upstream connections execute response phases on the produced HTTP 502 response. +--- skip_valgrind: 4 --- wasm_modules: on_phases --- tcp_listen: $TEST_NGINX_UNIX_SOCKET --- tcp_shutdown: 2 diff --git a/t/TestWasm.pm b/t/TestWasm.pm index 14638bec4..19099a219 100644 --- a/t/TestWasm.pm +++ b/t/TestWasm.pm @@ -31,6 +31,7 @@ our @EXPORT = qw( skip_no_debug skip_no_tinygo skip_valgrind + skip_hup ); $ENV{TEST_NGINX_USE_HUP} ||= 0; @@ -54,6 +55,9 @@ sub skip_valgrind (@) { if ($nver =~ m/$skip/) { plan skip_all => "skipped with Valgrind (nginx -V matches '$skip')"; + + } elsif ($skip eq "always") { + plan skip_all => "skipped with Valgrind (always)"; } return; @@ -64,6 +68,12 @@ sub skip_valgrind (@) { } } +sub skip_hup { + if ($ENV{TEST_NGINX_USE_HUP} == 1) { + plan(skip_all => "skipped in HUP mode"); + } +} + sub skip_no_debug { if ($nginxV !~ m/--with-debug/) { plan(skip_all => "--with-debug required (NGX_BUILD_DEBUG=1)"); @@ -209,13 +219,22 @@ add_block_preprocessor(sub { } } + my $skip_n; + my @block_skip = (); + + if (defined $block->skip_eval + && $block->skip_eval =~ m/\s*(\d+):\s*(.*)/) + { + push @block_skip, $2; + } + # --- skip_no_debug: 3 if (defined $block->skip_no_debug - && !defined $block->skip_eval && $block->skip_no_debug =~ m/\s*(\d+)/) { - $block->set_value("skip_eval", sprintf '%d: $::nginxV !~ m/--with-debug/', $1); + $skip_n = $1; + push @block_skip, '$::nginxV !~ m/--with-debug/'; } # --- skip_valgrind: 3 @@ -224,7 +243,13 @@ add_block_preprocessor(sub { && $ENV{TEST_NGINX_USE_VALGRIND} && $block->skip_valgrind =~ m/\s*(\d+)/) { - $block->set_value("skip_eval", sprintf '%d: $ENV{TEST_NGINX_USE_VALGRIND} && !$ENV{TEST_NGINX_USE_VALGRIND_ALL}', $1); + $skip_n = $1; + push @block_skip, '$ENV{TEST_NGINX_USE_VALGRIND}'; + } + + if (defined $skip_n) { + $block->set_value("skip_eval", sprintf('%d: (%s)', $skip_n, + join " || ", @block_skip)); } # --- timeout_expected: 1 diff --git a/t/lib/proxy-wasm-tests/context-checks/Cargo.toml b/t/lib/proxy-wasm-tests/context-checks/Cargo.toml new file mode 100644 index 000000000..65f7feee9 --- /dev/null +++ b/t/lib/proxy-wasm-tests/context-checks/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "context-checks" +version = "0.1.0" +authors = ["Thibault Charbonnier "] +edition = "2018" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +proxy-wasm = "0.2" +log = "0.4" diff --git a/t/lib/proxy-wasm-tests/context-checks/src/hostcalls.rs b/t/lib/proxy-wasm-tests/context-checks/src/hostcalls.rs new file mode 100644 index 000000000..d24c05f30 --- /dev/null +++ b/t/lib/proxy-wasm-tests/context-checks/src/hostcalls.rs @@ -0,0 +1,178 @@ +use crate::*; +use log::*; +use proxy_wasm::types::*; +use std::ptr::null_mut; + +#[allow(improper_ctypes)] +extern "C" { + fn proxy_log(level: u32, message_data: *const u8, message_size: usize) -> Status; +} + +pub fn log_something(_ctx: &TestContext) { + let msg = "proxy_log msg"; + unsafe { + let status = proxy_log(2, msg.as_ptr(), msg.len()); + info!("proxy_log status: {}", status as u32); + } +} + +#[allow(improper_ctypes)] +extern "C" { + fn proxy_set_tick_period_milliseconds(period: u32) -> Status; +} + +pub fn set_tick_period(_ctx: &TestContext) { + unsafe { + let status = proxy_set_tick_period_milliseconds(10000); + info!("set_tick_period status: {}", status as u32); + } +} + +#[allow(improper_ctypes)] +extern "C" { + fn proxy_set_buffer_bytes( + buffer_type: u32, + start: usize, + size: usize, + buffer_data: *const u8, + buffer_size: usize, + ) -> Status; +} + +pub fn set_request_body_buffer(_ctx: &TestContext) { + let v = String::default(); + + unsafe { + let status = proxy_set_buffer_bytes( + BufferType::HttpRequestBody as u32, + 0, + 0, + v.as_ptr(), + v.len(), + ); + + info!("set_request_body_buffer status: {}", status as u32); + } +} + +pub fn set_response_body_buffer(_ctx: &TestContext) { + let v = String::default(); + + unsafe { + let status = proxy_set_buffer_bytes( + BufferType::HttpResponseBody as u32, + 0, + 0, + v.as_ptr(), + v.len(), + ); + + info!("set_response_body_buffer status: {}", status as u32); + } +} + +#[allow(improper_ctypes)] +extern "C" { + fn proxy_get_buffer_bytes( + buffer_type: u32, + start: usize, + max_size: usize, + return_buffer_data: *mut *mut u8, + return_buffer_size: *mut usize, + ) -> Status; +} + +pub fn get_request_body_buffer(_ctx: &TestContext) { + let mut return_data: *mut u8 = null_mut(); + let mut return_size: usize = 0; + + unsafe { + let status = proxy_get_buffer_bytes( + BufferType::HttpRequestBody as u32, + 0, + 0, + &mut return_data, + &mut return_size, + ); + + info!("get_request_body_buffer status: {}", status as u32); + } +} + +pub fn get_response_body_buffer(_ctx: &TestContext) { + let mut return_data: *mut u8 = null_mut(); + let mut return_size: usize = 0; + + unsafe { + let status = proxy_get_buffer_bytes( + BufferType::HttpResponseBody as u32, + 0, + 0, + &mut return_data, + &mut return_size, + ); + + info!("get_response_body_buffer status: {}", status as u32); + } +} + +pub fn get_dispatch_response_body_buffer(_ctx: &TestContext) { + let mut return_data: *mut u8 = null_mut(); + let mut return_size: usize = 0; + + unsafe { + let status = proxy_get_buffer_bytes( + BufferType::HttpCallResponseBody as u32, + 0, + 0, + &mut return_data, + &mut return_size, + ); + + info!( + "get_dispatch_response_body_buffer status: {}", + status as u32 + ); + } +} + +#[allow(improper_ctypes)] +extern "C" { + fn proxy_http_call( + upstream_data: *const u8, + upstream_size: usize, + headers_data: *const u8, + headers_size: usize, + body_data: *const u8, + body_size: usize, + trailers_data: *const u8, + trailers_size: usize, + timeout: u32, + return_token: *mut u32, + ) -> Status; +} + +pub fn dispatch_http_call(_ctx: &TestContext) { + let upstream = ""; + let serialized_headers = ""; + let serialized_trailers = ""; + let body = ""; + let mut return_token: u32 = 0; + + unsafe { + let status = proxy_http_call( + upstream.as_ptr(), + 0, + serialized_headers.as_ptr(), + 0, + body.as_ptr(), + 0, + serialized_trailers.as_ptr(), + 0, + 0, + &mut return_token, + ); + + info!("dispatch_http_call status: {}", status as u32); + } +} diff --git a/t/lib/proxy-wasm-tests/context-checks/src/lib.rs b/t/lib/proxy-wasm-tests/context-checks/src/lib.rs new file mode 100644 index 000000000..8241b1c75 --- /dev/null +++ b/t/lib/proxy-wasm-tests/context-checks/src/lib.rs @@ -0,0 +1,213 @@ +mod hostcalls; + +use crate::hostcalls::*; +use log::*; +use proxy_wasm::{traits::*, types::*}; +use std::collections::HashMap; +use std::time::Duration; + +pub struct TestContext { + config: HashMap, +} + +impl TestContext { + fn get_config(&self, name: &str) -> Option<&str> { + self.config.get(name).map(|s| s.as_str()) + } + + fn check_host_function(&self, name: &str) { + match name { + "proxy_log" => log_something(self), + "set_tick_period" => set_tick_period(self), + "set_request_body_buffer" => set_request_body_buffer(self), + "set_response_body_buffer" => set_response_body_buffer(self), + "get_request_body_buffer" => get_request_body_buffer(self), + "get_response_body_buffer" => get_response_body_buffer(self), + "get_dispatch_response_body_buffer" => get_dispatch_response_body_buffer(self), + "dispatch_http_call" => dispatch_http_call(self), + _ => (), + } + } +} + +struct TestRoot { + tester: TestContext, +} + +struct TestHttp { + tester: TestContext, +} + +proxy_wasm::main! {{ + proxy_wasm::set_log_level(LogLevel::Trace); + proxy_wasm::set_root_context(|_| -> Box { + Box::new(TestRoot { + tester: TestContext { + config: HashMap::new(), + } + }) + }); +}} + +impl HttpContext for TestHttp { + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + if let Some(name) = self.tester.get_config("on_request_headers") { + self.tester.check_host_function(name); + } else if self + .tester + .get_config("on_http_dispatch_response") + .is_some() + { + let _ = self.dispatch_http_call( + self.tester.get_config("host").unwrap_or(""), + vec![(":path", "/dispatch"), (":method", "GET")], + None, + vec![], + Duration::from_secs(0), + ); + + return Action::Pause; + } + + Action::Continue + } + + fn on_http_request_body(&mut self, _: usize, _: bool) -> Action { + if let Some(name) = self.tester.get_config("on_request_body") { + self.tester.check_host_function(name); + } + + Action::Continue + } + + fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { + if let Some(name) = self.tester.get_config("on_response_headers") { + self.tester.check_host_function(name); + } + + Action::Continue + } + + fn on_http_response_body(&mut self, _: usize, _: bool) -> Action { + if let Some(name) = self.tester.get_config("on_response_body") { + self.tester.check_host_function(name); + } + + Action::Continue + } + + fn on_log(&mut self) { + if let Some(name) = self.tester.get_config("on_log") { + self.tester.check_host_function(name); + } + } +} + +impl Context for TestHttp { + fn on_http_call_response( + &mut self, + token_id: u32, + nheaders: usize, + body_size: usize, + ntrailers: usize, + ) { + let status = self.get_http_call_response_header(":status"); + + info!( + "on_http_call_response (id: {}, status: {}, headers: {}, body_bytes: {}, trailers: {})", + token_id, + status.unwrap_or("".to_string()), + nheaders, + body_size, + ntrailers + ); + + if let Some(name) = self.tester.get_config("on_http_dispatch_response") { + self.tester.check_host_function(name); + } + } +} + +impl RootContext for TestRoot { + fn on_vm_start(&mut self, _: usize) -> bool { + info!("on_vm_start"); + + if let Some(config) = self.get_vm_configuration() { + match std::str::from_utf8(&config) { + Ok(text) => { + info!("vm config: {}", text); + self.tester.check_host_function(text); + } + _ => info!("cannot parse vm config"), + } + } + + true + } + + fn on_configure(&mut self, _: usize) -> bool { + info!("on_configure"); + + if let Some(config_bytes) = self.get_plugin_configuration() { + let config_str = String::from_utf8(config_bytes).unwrap(); + self.tester.config = config_str + .split_whitespace() + .filter_map(|s| s.split_once('=')) + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect(); + } else { + self.tester.config = HashMap::new(); + } + + if self.tester.get_config("on_tick").is_some() { + self.set_tick_period(Duration::from_millis(100)); + } + + if let Some(name) = self.tester.get_config("on_configure") { + self.tester.check_host_function(name); + } + + true + } + + fn on_tick(&mut self) { + info!("on_tick",); + + if let Some(name) = self.tester.get_config("on_tick") { + self.tester.check_host_function(name); + } + } + + fn get_type(&self) -> Option { + Some(ContextType::HttpContext) + } + + fn create_http_context(&self, _: u32) -> Option> { + Some(Box::new(TestHttp { + tester: TestContext { + config: self.tester.config.clone(), + }, + })) + } +} + +impl Context for TestRoot { + fn on_http_call_response( + &mut self, + token_id: u32, + nheaders: usize, + body_size: usize, + ntrailers: usize, + ) { + let status = self.get_http_call_response_header(":status"); + + info!( + "on_root_http_call_response (id: {}, status: {}, headers: {}, body_bytes: {}, trailers: {})", + token_id, status.unwrap_or("".to_string()), nheaders, body_size, ntrailers + ); + + if let Some(name) = self.tester.get_config("on_http_dispatch_response") { + self.tester.check_host_function(name); + } + } +} diff --git a/valgrind.suppress b/valgrind.suppress index c3b011f51..b6e487c7a 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -25,10 +25,9 @@ Memcheck:Cond fun:ngx_http_set_header_helper + ... fun:ngx_http_headers_more_exec_cmd fun:ngx_http_headers_more_filter - ... - fun:main } {