diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5f33284 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,40 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: "ubuntu-18.04" + env: + OPENRESTY_PREFIX: "/usr/local/openresty" + + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Get dependencies + run: | + sudo apt install -y cpanminus build-essential libncurses5-dev libreadline-dev libssl-dev perl + wget https://github.com/tinygo-org/tinygo/releases/download/v0.19.0/tinygo_0.19.0_amd64.deb + sudo dpkg -i tinygo_0.19.0_amd64.deb + + - name: Before install + run: | + sudo cpanm --notest Test::Nginx > build.log 2>&1 || (cat build.log && exit 1) + git clone https://github.com/iresty/test-nginx.git test-nginx + + - name: Install + run: | + wget https://raw.githubusercontent.com/api7/apisix-build-tools/master/build-apisix-base.sh + chmod +x build-apisix-base.sh + OR_PREFIX=$OPENRESTY_PREFIX ./build-apisix-base.sh latest + + - name: Script + run: | + make build.all.testdata + export PATH=$OPENRESTY_PREFIX/nginx/sbin:$PATH + prove -I. -Itest-nginx/lib -r t/ diff --git a/src/vm/wasmtime.c b/src/vm/wasmtime.c index ff1e27b..a2e4364 100644 --- a/src/vm/wasmtime.c +++ b/src/vm/wasmtime.c @@ -72,6 +72,7 @@ static void * ngx_wasm_wasmtime_load(const char *bytecode, size_t size) { size_t i; + bool ok; wasm_trap_t *trap = NULL; wasmtime_module_t *module; wasmtime_store_t *store; @@ -79,8 +80,8 @@ ngx_wasm_wasmtime_load(const char *bytecode, size_t size) wasi_config_t *wasi_config; wasmtime_error_t *error; ngx_wasm_wasmtime_plugin_t *plugin; + wasmtime_extern_t item; - // TODO: separate WASM compiling from the store init error = wasmtime_module_new(vm_engine, (const uint8_t*) bytecode, size, &module); if (module == NULL) { return NULL; @@ -98,7 +99,6 @@ ngx_wasm_wasmtime_load(const char *bytecode, size_t size) goto free_store; } - wasi_config_inherit_argv(wasi_config); wasi_config_inherit_env(wasi_config); wasi_config_inherit_stdin(wasi_config); wasi_config_inherit_stdout(wasi_config); @@ -152,8 +152,6 @@ ngx_wasm_wasmtime_load(const char *bytecode, size_t size) goto free_linker; } - wasmtime_extern_t item; - bool ok; ok = wasmtime_instance_export_get(context, &plugin->instance, "memory", strlen("memory"), &item); if (!ok || item.kind != WASMTIME_EXTERN_MEMORY) { ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "the wasm plugin doesn't export memory"); diff --git a/t/WASM.pm b/t/WASM.pm index f65f46f..1ef10ed 100644 --- a/t/WASM.pm +++ b/t/WASM.pm @@ -7,6 +7,7 @@ use Cwd qw(cwd); log_level('info'); no_long_string(); no_shuffle(); +master_on(); worker_connections(128); diff --git a/t/plugin_lifecycle.t b/t/plugin_lifecycle.t index db20d55..7aee5a5 100644 --- a/t/plugin_lifecycle.t +++ b/t/plugin_lifecycle.t @@ -151,7 +151,7 @@ location /t { for i = 1, 2 do do local plugin = wasm.load("t/testdata/plugin_lifecycle/main.go.wasm") - for i = 1, 2 do + for j = 1, 2 do local ctx = assert(wasm.on_configure(plugin, '{"body":512}')) end end