《潘泳权wpac-应用waPC (rust) 做软件测试工具.pptx》由会员分享,可在线阅读,更多相关《潘泳权wpac-应用waPC (rust) 做软件测试工具.pptx(30页珍藏版)》请在三个皮匠报告上搜索。
1、第三届中国第三届中国Rust开发者大会开发者大会应用应用waPC(rust)做软件测试工具做软件测试工具Alan poon 潘泳权大家好!rustropy_gamingruito_89PhoTto/image/chartWebassembly Procedures CallwaPC 协议标准化了本机代码调用 WebAssembly 和 WebAssembly 调用本机代码的通信通信(messaging)和错误错误处理处理(error handling)。什么是waPC?WASM外部函数接口 FFIInput type Return typePlatform底层底层I32I32Unknownwa
2、PC&u8ResultVec,errorLinux x86_64,macOS x86_64,Windows x86_64,cargo build target wasm-unknown-unknownwaPC Host(Go)waPC Guest RustRead wasm fileSelect engineWazeroWasmer-goWasmertime-goDefine hostcall capabilityInstantiateInvoke-command with dataGuest 指wasmOperation是我们要在wasm里注册命名以数据的长度,设置wasm 的linear
3、memory 的指针Guest可执行任务Guest也可返回请求hostInvoke(ctx,operation,payload)WAPC 流程Uses Length of response and error to return resultres,err:=InvokeWAPC 流程#no_manglepub fn wapc_init()wapc:register_function(ping,ping);fn ping(msg:&u8)-wapc:CallResult.Ok(msg.to_vec()waPC Guest RustwaPCUse wapc_init to register fu
4、nctionRegister_function can only be used inside WAPC_initRegister_function cannot be called inside ping_start is meant to support tinygos wasmwaPC host will still run both wapc_init and _start during intializationwaPC Guest RustwaPC Use wapc_init to register function _start also canUtil Lib uses wap
5、c_init,users build on top of”_start”extern crate wapc_guest as guest;extern crate Regex;.fn echo_req_json(msg:&u8)-CallResult let mut req=foo_unmarshall:(msg)?;let re=Regex:new(r”/v2/matches/(a-zA-Z0-9_-+)/info).unwrap();if let Some(cap)=re.captures(&req.HttpPath)req.HttpProxyUrl=String:from(“localh
6、ost:8000);req.HttpScheme=String:from(http);let request=serde_json:to_string(&req)?;Ok(request.as_bytes().to_vec()fn do_nothing(msg:&u8)-CallResult Ok(msg.to_vec()#no_manglepub extern C fn _start()let mut reg=REGISTRY.lock().unwrap();reg.insert(“/v2/matches/.*/info_modify_req”.into(),echo_req_json);r