diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index afe650e..833d35c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -139,6 +139,7 @@ jobs: with: repository: proxy-wasm/proxy-wasm-rust-sdk path: proxy-wasm-rust-sdk + ref: v0.2.1 - name: Update Rust run: | @@ -174,16 +175,19 @@ jobs: - name: Build (Rust SDK examples) env: RUSTFLAGS: -C link-args=-S -D warnings - run: cd proxy-wasm-rust-sdk && cargo build --release --examples --target=wasm32-unknown-unknown && cd .. + run: | + cd proxy-wasm-rust-sdk/examples/hello_world && cargo build --target wasm32-unknown-unknown --release && cd ../../.. + cd proxy-wasm-rust-sdk/examples/http_auth_random && cargo build --target wasm32-unknown-unknown --release && cd ../../.. + cd proxy-wasm-rust-sdk/examples/http_headers && cargo build --target wasm32-unknown-unknown --release && cd ../../.. - name: Test (hello_world) - run: target/release/examples/hello_world proxy-wasm-rust-sdk/target/wasm32-unknown-unknown/release/examples/hello_world.wasm + run: target/release/examples/hello_world proxy-wasm-rust-sdk/examples/hello_world/target/wasm32-unknown-unknown/release/proxy_wasm_example_hello_world.wasm - name: Test (http_auth_random) - run: target/release/examples/http_auth_random proxy-wasm-rust-sdk/target/wasm32-unknown-unknown/release/examples/http_auth_random.wasm -a + run: target/release/examples/http_auth_random proxy-wasm-rust-sdk/examples/http_auth_random/target/wasm32-unknown-unknown/release/proxy_wasm_example_http_auth_random.wasm -a - name: Test (http_headers) - run: target/release/examples/http_headers proxy-wasm-rust-sdk/target/wasm32-unknown-unknown/release/examples/http_headers.wasm -a + run: target/release/examples/http_headers proxy-wasm-rust-sdk/examples/http_headers/target/wasm32-unknown-unknown/release/proxy_wasm_example_http_headers.wasm -a outdated: runs-on: ubuntu-latest diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 1ebd974..4552bf5 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -40,7 +40,10 @@ fn main() -> Result<()> { .call_proxy_on_tick(root_context) .expect_get_current_time_nanos() .returning(Some(0 * 10u64.pow(9))) - .expect_log(Some(LogLevel::Info), Some("It's 1970-01-01 00:00:00 UTC")) + .expect_log( + Some(LogLevel::Info), + Some("It's 1970-01-01 00:00:00 UTC, there is no lucky number."), + ) .execute_and_expect(ReturnType::None)?; hello_world_test diff --git a/examples/http_headers.rs b/examples/http_headers.rs index 1aed448..56fe1a4 100644 --- a/examples/http_headers.rs +++ b/examples/http_headers.rs @@ -57,13 +57,13 @@ fn main() -> Result<()> { .call_proxy_on_response_headers(http_context, 0, false) .expect_get_header_map_pairs(Some(MapType::HttpResponseHeaders)) .returning(Some(vec![(":status", "200"), ("Powered-By", "proxy-wasm")])) - .expect_log(Some(LogLevel::Trace), Some("#2 <- :status: 200")) - .expect_log(Some(LogLevel::Trace), Some("#2 <- Powered-By: proxy-wasm")) + .expect_log(Some(LogLevel::Info), Some("#2 <- :status: 200")) + .expect_log(Some(LogLevel::Info), Some("#2 <- Powered-By: proxy-wasm")) .execute_and_expect(ReturnType::Action(Action::Continue))?; http_headers_test .call_proxy_on_log(http_context) - .expect_log(Some(LogLevel::Trace), Some("#2 completed.")) + .expect_log(Some(LogLevel::Info), Some("#2 completed.")) .execute_and_expect(ReturnType::None)?; return Ok(()); diff --git a/src/hostcalls.rs b/src/hostcalls.rs index 54cb163..3323f82 100644 --- a/src/hostcalls.rs +++ b/src/hostcalls.rs @@ -41,7 +41,9 @@ pub fn get_status() -> ExpectStatus { pub fn get_abi_version(module: &Module) -> AbiVersion { if module.get_export("proxy_abi_version_0_1_0").is_some() { AbiVersion::ProxyAbiVersion0_1_0 - } else if module.get_export("proxy_abi_version_0_2_0").is_some() { + } else if module.get_export("proxy_abi_version_0_2_0").is_some() + || module.get_export("proxy_abi_version_0_2_1").is_some() + { AbiVersion::ProxyAbiVersion0_2_0 } else { panic!("Error: test-framework does not support proxy-wasm modules of this abi version"); @@ -320,41 +322,53 @@ fn get_hostfunc( /* ---------------------------------- Continue/Close/Reply/Route ---------------------------------- */ "proxy_continue_stream" => { - Some(Func::wrap(store, |_caller: Caller<'_, ()>| -> i32 { - // Default Function: - // Expectation: - assert_eq!( - HOST.lock().unwrap().staged.get_abi_version(), - AbiVersion::ProxyAbiVersion0_2_0 - ); - println!( - "[vm->host] proxy_continue_stream() status: {:?}", - get_status() - ); - println!( - "[vm<-host] proxy_continue_stream() return: {:?}", - Status::Ok - ); - assert_ne!(get_status(), ExpectStatus::Failed); - set_status(ExpectStatus::Unexpected); - return Status::Ok as i32; - })) + Some(Func::wrap( + store, + |_caller: Caller<'_, ()>, stream_type: i32| -> i32 { + // Default Function: + // Expectation: + assert_eq!( + HOST.lock().unwrap().staged.get_abi_version(), + AbiVersion::ProxyAbiVersion0_2_0 + ); + println!( + "[vm->host] proxy_continue_stream(stream_type={stream_type}) status: {:?}", + get_status() + ); + println!( + "[vm<-host] proxy_continue_stream(...) return: {:?}", + Status::Ok + ); + assert_ne!(get_status(), ExpectStatus::Failed); + set_status(ExpectStatus::Unexpected); + return Status::Ok as i32; + }, + )) } "proxy_close_stream" => { - Some(Func::wrap(store, |_caller: Caller<'_, ()>| -> i32 { - // Default Function: - // Expectation: - assert_eq!( - HOST.lock().unwrap().staged.get_abi_version(), - AbiVersion::ProxyAbiVersion0_2_0 - ); - println!("[vm->host] proxy_close_stream() status: {:?}", get_status()); - println!("[vm<-host] proxy_close_stream() return: {:?}", Status::Ok); - assert_ne!(get_status(), ExpectStatus::Failed); - set_status(ExpectStatus::Unexpected); - return Status::Ok as i32; - })) + Some(Func::wrap( + store, + |_caller: Caller<'_, ()>, stream_type: i32| -> i32 { + // Default Function: + // Expectation: + assert_eq!( + HOST.lock().unwrap().staged.get_abi_version(), + AbiVersion::ProxyAbiVersion0_2_0 + ); + println!( + "[vm->host] proxy_close_stream(stream_type={stream_type}) status: {:?}", + get_status() + ); + println!( + "[vm<-host] proxy_close_stream(...) return: {:?}", + Status::Ok + ); + assert_ne!(get_status(), ExpectStatus::Failed); + set_status(ExpectStatus::Unexpected); + return Status::Ok as i32; + }, + )) } "proxy_continue_request" => { diff --git a/src/tester.rs b/src/tester.rs index 57c2846..9c74b40 100644 --- a/src/tester.rs +++ b/src/tester.rs @@ -362,13 +362,25 @@ impl Tester { let mut return_wasm: Option = None; match self.function_call.remove(0) { FunctionCall::Start() => { - println!("[host->vm] _start()"); - self.instance - .get_typed_func::<(), ()>(&mut self.store, "_start") + let (name, func) = self + .instance + .get_typed_func::<(), ()>(&mut self.store, "_initialize") + .map(|func| ("_initialize", func)) + .or_else(|_| { + self.instance + .get_typed_func::<(), ()>(&mut self.store, "main") + .map(|func| ("main", func)) + }) + .or_else(|_| { + self.instance + .get_typed_func::<(), ()>(&mut self.store, "_start") + .map(|func| ("_start", func)) + }) .or(Err(anyhow::format_err!( - "Error: failed to find `_start` function export" - )))? - .call(&mut self.store, ())?; + "Error: failed to find `_initialize`, `main` or `_start` function export" + )))?; + println!("[host->vm] {name}()"); + func.call(&mut self.store, ())?; } FunctionCall::ProxyOnVmStart(context_id, vm_configuration_size) => {