Skip to content

Commit 1dca120

Browse files
authored
Fix testing examples. (#16)
Signed-off-by: Alex Snaps <[email protected]>
1 parent 9fbb3f8 commit 1dca120

File tree

5 files changed

+80
-47
lines changed

5 files changed

+80
-47
lines changed

.github/workflows/rust.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ jobs:
139139
with:
140140
repository: proxy-wasm/proxy-wasm-rust-sdk
141141
path: proxy-wasm-rust-sdk
142+
ref: v0.2.1
142143

143144
- name: Update Rust
144145
run: |
@@ -174,16 +175,19 @@ jobs:
174175
- name: Build (Rust SDK examples)
175176
env:
176177
RUSTFLAGS: -C link-args=-S -D warnings
177-
run: cd proxy-wasm-rust-sdk && cargo build --release --examples --target=wasm32-unknown-unknown && cd ..
178+
run: |
179+
cd proxy-wasm-rust-sdk/examples/hello_world && cargo build --target wasm32-unknown-unknown --release && cd ../../..
180+
cd proxy-wasm-rust-sdk/examples/http_auth_random && cargo build --target wasm32-unknown-unknown --release && cd ../../..
181+
cd proxy-wasm-rust-sdk/examples/http_headers && cargo build --target wasm32-unknown-unknown --release && cd ../../..
178182
179183
- name: Test (hello_world)
180-
run: target/release/examples/hello_world proxy-wasm-rust-sdk/target/wasm32-unknown-unknown/release/examples/hello_world.wasm
184+
run: target/release/examples/hello_world proxy-wasm-rust-sdk/examples/hello_world/target/wasm32-unknown-unknown/release/proxy_wasm_example_hello_world.wasm
181185

182186
- name: Test (http_auth_random)
183-
run: target/release/examples/http_auth_random proxy-wasm-rust-sdk/target/wasm32-unknown-unknown/release/examples/http_auth_random.wasm -a
187+
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
184188

185189
- name: Test (http_headers)
186-
run: target/release/examples/http_headers proxy-wasm-rust-sdk/target/wasm32-unknown-unknown/release/examples/http_headers.wasm -a
190+
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
187191

188192
outdated:
189193
runs-on: ubuntu-latest

examples/hello_world.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ fn main() -> Result<()> {
4040
.call_proxy_on_tick(root_context)
4141
.expect_get_current_time_nanos()
4242
.returning(Some(0 * 10u64.pow(9)))
43-
.expect_log(Some(LogLevel::Info), Some("It's 1970-01-01 00:00:00 UTC"))
43+
.expect_log(
44+
Some(LogLevel::Info),
45+
Some("It's 1970-01-01 00:00:00 UTC, there is no lucky number."),
46+
)
4447
.execute_and_expect(ReturnType::None)?;
4548

4649
hello_world_test

examples/http_headers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ fn main() -> Result<()> {
5757
.call_proxy_on_response_headers(http_context, 0, false)
5858
.expect_get_header_map_pairs(Some(MapType::HttpResponseHeaders))
5959
.returning(Some(vec![(":status", "200"), ("Powered-By", "proxy-wasm")]))
60-
.expect_log(Some(LogLevel::Trace), Some("#2 <- :status: 200"))
61-
.expect_log(Some(LogLevel::Trace), Some("#2 <- Powered-By: proxy-wasm"))
60+
.expect_log(Some(LogLevel::Info), Some("#2 <- :status: 200"))
61+
.expect_log(Some(LogLevel::Info), Some("#2 <- Powered-By: proxy-wasm"))
6262
.execute_and_expect(ReturnType::Action(Action::Continue))?;
6363

6464
http_headers_test
6565
.call_proxy_on_log(http_context)
66-
.expect_log(Some(LogLevel::Trace), Some("#2 completed."))
66+
.expect_log(Some(LogLevel::Info), Some("#2 completed."))
6767
.execute_and_expect(ReturnType::None)?;
6868

6969
return Ok(());

src/hostcalls.rs

+47-33
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ pub fn get_status() -> ExpectStatus {
4141
pub fn get_abi_version(module: &Module) -> AbiVersion {
4242
if module.get_export("proxy_abi_version_0_1_0").is_some() {
4343
AbiVersion::ProxyAbiVersion0_1_0
44-
} else if module.get_export("proxy_abi_version_0_2_0").is_some() {
44+
} else if module.get_export("proxy_abi_version_0_2_0").is_some()
45+
|| module.get_export("proxy_abi_version_0_2_1").is_some()
46+
{
4547
AbiVersion::ProxyAbiVersion0_2_0
4648
} else {
4749
panic!("Error: test-framework does not support proxy-wasm modules of this abi version");
@@ -320,41 +322,53 @@ fn get_hostfunc(
320322

321323
/* ---------------------------------- Continue/Close/Reply/Route ---------------------------------- */
322324
"proxy_continue_stream" => {
323-
Some(Func::wrap(store, |_caller: Caller<'_, ()>| -> i32 {
324-
// Default Function:
325-
// Expectation:
326-
assert_eq!(
327-
HOST.lock().unwrap().staged.get_abi_version(),
328-
AbiVersion::ProxyAbiVersion0_2_0
329-
);
330-
println!(
331-
"[vm->host] proxy_continue_stream() status: {:?}",
332-
get_status()
333-
);
334-
println!(
335-
"[vm<-host] proxy_continue_stream() return: {:?}",
336-
Status::Ok
337-
);
338-
assert_ne!(get_status(), ExpectStatus::Failed);
339-
set_status(ExpectStatus::Unexpected);
340-
return Status::Ok as i32;
341-
}))
325+
Some(Func::wrap(
326+
store,
327+
|_caller: Caller<'_, ()>, stream_type: i32| -> i32 {
328+
// Default Function:
329+
// Expectation:
330+
assert_eq!(
331+
HOST.lock().unwrap().staged.get_abi_version(),
332+
AbiVersion::ProxyAbiVersion0_2_0
333+
);
334+
println!(
335+
"[vm->host] proxy_continue_stream(stream_type={stream_type}) status: {:?}",
336+
get_status()
337+
);
338+
println!(
339+
"[vm<-host] proxy_continue_stream(...) return: {:?}",
340+
Status::Ok
341+
);
342+
assert_ne!(get_status(), ExpectStatus::Failed);
343+
set_status(ExpectStatus::Unexpected);
344+
return Status::Ok as i32;
345+
},
346+
))
342347
}
343348

344349
"proxy_close_stream" => {
345-
Some(Func::wrap(store, |_caller: Caller<'_, ()>| -> i32 {
346-
// Default Function:
347-
// Expectation:
348-
assert_eq!(
349-
HOST.lock().unwrap().staged.get_abi_version(),
350-
AbiVersion::ProxyAbiVersion0_2_0
351-
);
352-
println!("[vm->host] proxy_close_stream() status: {:?}", get_status());
353-
println!("[vm<-host] proxy_close_stream() return: {:?}", Status::Ok);
354-
assert_ne!(get_status(), ExpectStatus::Failed);
355-
set_status(ExpectStatus::Unexpected);
356-
return Status::Ok as i32;
357-
}))
350+
Some(Func::wrap(
351+
store,
352+
|_caller: Caller<'_, ()>, stream_type: i32| -> i32 {
353+
// Default Function:
354+
// Expectation:
355+
assert_eq!(
356+
HOST.lock().unwrap().staged.get_abi_version(),
357+
AbiVersion::ProxyAbiVersion0_2_0
358+
);
359+
println!(
360+
"[vm->host] proxy_close_stream(stream_type={stream_type}) status: {:?}",
361+
get_status()
362+
);
363+
println!(
364+
"[vm<-host] proxy_close_stream(...) return: {:?}",
365+
Status::Ok
366+
);
367+
assert_ne!(get_status(), ExpectStatus::Failed);
368+
set_status(ExpectStatus::Unexpected);
369+
return Status::Ok as i32;
370+
},
371+
))
358372
}
359373

360374
"proxy_continue_request" => {

src/tester.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,25 @@ impl Tester {
362362
let mut return_wasm: Option<i32> = None;
363363
match self.function_call.remove(0) {
364364
FunctionCall::Start() => {
365-
println!("[host->vm] _start()");
366-
self.instance
367-
.get_typed_func::<(), ()>(&mut self.store, "_start")
365+
let (name, func) = self
366+
.instance
367+
.get_typed_func::<(), ()>(&mut self.store, "_initialize")
368+
.map(|func| ("_initialize", func))
369+
.or_else(|_| {
370+
self.instance
371+
.get_typed_func::<(), ()>(&mut self.store, "main")
372+
.map(|func| ("main", func))
373+
})
374+
.or_else(|_| {
375+
self.instance
376+
.get_typed_func::<(), ()>(&mut self.store, "_start")
377+
.map(|func| ("_start", func))
378+
})
368379
.or(Err(anyhow::format_err!(
369-
"Error: failed to find `_start` function export"
370-
)))?
371-
.call(&mut self.store, ())?;
380+
"Error: failed to find `_initialize`, `main` or `_start` function export"
381+
)))?;
382+
println!("[host->vm] {name}()");
383+
func.call(&mut self.store, ())?;
372384
}
373385

374386
FunctionCall::ProxyOnVmStart(context_id, vm_configuration_size) => {

0 commit comments

Comments
 (0)