Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi-tls-openssl/tests/main.rs
3090 views
1
use wasmtime::{
2
Result, Store,
3
component::{Component, Linker, ResourceTable},
4
format_err,
5
};
6
use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView, p2::bindings::Command};
7
use wasmtime_wasi_tls::{LinkOptions, WasiTls, WasiTlsCtx, WasiTlsCtxBuilder};
8
9
struct Ctx {
10
table: ResourceTable,
11
wasi_ctx: WasiCtx,
12
wasi_tls_ctx: WasiTlsCtx,
13
}
14
15
impl WasiView for Ctx {
16
fn ctx(&mut self) -> WasiCtxView<'_> {
17
WasiCtxView {
18
ctx: &mut self.wasi_ctx,
19
table: &mut self.table,
20
}
21
}
22
}
23
24
async fn run_test(path: &str) -> Result<()> {
25
let provider = Box::new(wasmtime_wasi_tls_openssl::OpenSslProvider::default());
26
let ctx = Ctx {
27
table: ResourceTable::new(),
28
wasi_ctx: WasiCtx::builder()
29
.inherit_stderr()
30
.inherit_network()
31
.allow_ip_name_lookup(true)
32
.build(),
33
wasi_tls_ctx: WasiTlsCtxBuilder::new().provider(provider).build(),
34
};
35
36
let engine = test_programs_artifacts::engine(|_config| {});
37
let mut store = Store::new(&engine, ctx);
38
let component = Component::from_file(&engine, path)?;
39
40
let mut linker = Linker::new(&engine);
41
wasmtime_wasi::p2::add_to_linker_async(&mut linker)?;
42
let mut opts = LinkOptions::default();
43
opts.tls(true);
44
wasmtime_wasi_tls::add_to_linker(&mut linker, &mut opts, |h: &mut Ctx| {
45
WasiTls::new(&h.wasi_tls_ctx, &mut h.table)
46
})?;
47
48
let command = Command::instantiate_async(&mut store, &component, &linker).await?;
49
command
50
.wasi_cli_run()
51
.call_run(&mut store)
52
.await?
53
.map_err(|()| format_err!("command returned with failing exit status"))
54
}
55
56
macro_rules! assert_test_exists {
57
($name:ident) => {
58
#[expect(unused_imports, reason = "just here to assert it exists")]
59
use self::$name as _;
60
};
61
}
62
63
test_programs_artifacts::foreach_tls!(assert_test_exists);
64
65
#[tokio::test(flavor = "multi_thread")]
66
async fn tls_sample_application() -> Result<()> {
67
run_test(test_programs_artifacts::TLS_SAMPLE_APPLICATION_COMPONENT).await
68
}
69
70