Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions crates/test/src/c.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::StringList;
use crate::{Compile, Kind, LanguageMethods, Runner, Verify};
use crate::{Compile, LanguageMethods, Runner, Verify};
use anyhow::{Context, Result};
use clap::Parser;
use heck::ToSnakeCase;
Expand Down Expand Up @@ -144,12 +144,7 @@ fn compile(runner: &Runner<'_>, compile: &Compile<'_>, compiler: PathBuf) -> Res
for flag in Vec::from(config.cflags) {
cmd.arg(flag);
}
match compile.component.kind {
Kind::Runner => {}
Kind::Test => {
cmd.arg("-mexec-model=reactor");
}
}
cmd.arg("-mexec-model=reactor");
if produces_component(runner) {
cmd.arg("-Wl,--skip-wit-component");
}
Expand Down
9 changes: 2 additions & 7 deletions crates/test/src/cpp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::StringList;
use crate::{Kind, LanguageMethods, Runner};
use crate::{LanguageMethods, Runner};
use anyhow::Context;
use heck::ToSnakeCase;
use serde::Deserialize;
Expand Down Expand Up @@ -174,12 +174,7 @@ impl LanguageMethods for Cpp {
for flag in Vec::from(config.cflags) {
cmd.arg(flag);
}
match compile.component.kind {
Kind::Runner => {}
Kind::Test => {
cmd.arg("-mexec-model=reactor");
}
}
cmd.arg("-mexec-model=reactor");
runner.run_command(&mut cmd)?;
Ok(())
}
Expand Down
5 changes: 1 addition & 4 deletions crates/test/src/csharp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Compile, Kind, LanguageMethods, Runner, Verify};
use crate::{Compile, LanguageMethods, Runner, Verify};
use anyhow::Result;
use heck::*;
use std::env;
Expand Down Expand Up @@ -75,9 +75,6 @@ impl LanguageMethods for Csharp {
let mut csproj =
wit_bindgen_csharp::CSProject::new(test_dir.to_path_buf(), &assembly_name, world_name);
csproj.aot();
if let Kind::Runner = compile.component.kind {
csproj.binary();
}
csproj.generate()?;

let mut cmd = dotnet();
Expand Down
10 changes: 2 additions & 8 deletions crates/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,14 +1030,8 @@ status: {}",
section.encode(&mut module);
}

let wasi_adapter = match compile.component.kind {
Kind::Runner => {
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_COMMAND_ADAPTER
}
Kind::Test => {
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER
}
};
let wasi_adapter =
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER;

let component = ComponentEncoder::default()
.module(module.as_slice())
Expand Down
1 change: 1 addition & 0 deletions crates/test/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl TestRunner {
for arg in self.args.iter() {
ret.arg(arg);
}
ret.arg("--invoke=run()");
ret
}
}
9 changes: 2 additions & 7 deletions crates/test/src/rust.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::StringList;
use crate::{Compile, Kind, LanguageMethods, Runner, Verify};
use crate::{Compile, LanguageMethods, Runner, Verify};
use anyhow::{Context, Result};
use clap::Parser;
use heck::ToSnakeCase;
Expand Down Expand Up @@ -206,12 +206,7 @@ path = 'lib.rs'
let arg = format!("--extern={name}={}", path.display());
cmd.arg(arg);
}
match compile.component.kind {
Kind::Runner => {}
Kind::Test => {
cmd.arg("--crate-type=cdylib");
}
}
cmd.arg("--crate-type=cdylib");
if runner.produces_component() {
cmd.arg("-Clink-arg=--skip-wit-component");
}
Expand Down
4 changes: 2 additions & 2 deletions tests/runtime-async/async/cancel-import/runner.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//@ args = '--rename my:test/i=test'
//@ args = '--rename my:test/i=test --async=-run'

#include <assert.h>
#include <runner.h>

int main() {
void exports_runner_run() {
// Call an import and cancel it.
{
test_future_void_writer_t writer;
Expand Down
242 changes: 124 additions & 118 deletions tests/runtime-async/async/cancel-import/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,128 +6,134 @@ use std::future::Future;
use std::task::Context;
use wit_bindgen::yield_async;

fn main() {
println!("test cancelling an import in progress");
wit_bindgen::block_on(async {
let (tx, rx) = wit_future::new(|| unreachable!());
let mut import = Box::pin(pending_import(rx));
assert!(import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());
drop(import);
tx.write(()).await.unwrap_err();
});

println!("test cancelling an import before it starts");
wit_bindgen::block_on(async {
let (tx, rx) = wit_future::new(|| unreachable!());
let import = Box::pin(pending_import(rx));
drop(import);
tx.write(()).await.unwrap_err();
});

println!("test cancelling an import in the started state");
wit_bindgen::block_on(async {
let (tx1, rx1) = wit_future::new(|| unreachable!());
let (tx2, rx2) = wit_future::new(|| unreachable!());

// create a task in the "started" state, but don't complete it yet
let mut started_import = Box::pin(pending_import(rx1));
assert!(started_import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// request the other component sets its backpressure flag meaning we
// won't be able to create new tasks in the "started" state.
backpressure_set(true);
let mut starting_import = Box::pin(pending_import(rx2));
assert!(starting_import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// Now cancel the "starting" import. This should notably drop handles in
// arguments since they get re-acquired during cancellation
drop(starting_import);

// cancel our in-progress export
drop(started_import);

backpressure_set(false);

// both channels should be dropped
tx1.write(()).await.unwrap_err();
tx2.write(()).await.unwrap_err();
});

// Race an import's cancellation with a status code saying it's done.
println!("test cancellation with a status code saying it's done");
wit_bindgen::block_on(async {
// Start a subtask and get it into the "started" state
let (tx, rx) = wit_future::new(|| unreachable!());
let mut import = Box::pin(pending_import(rx));
assert!(import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// Complete the subtask, but don't see the completion in Rust yet.
tx.write(()).await.unwrap();

// Let the subtask's completion notification make its way to our task
// here.
for _ in 0..5 {
yield_async().await;
struct Component;

export!(Component);

impl Guest for Component {
async fn run() {
println!("test cancelling an import in progress");
{
let (tx, rx) = wit_future::new(|| unreachable!());
let mut import = Box::pin(pending_import(rx));
assert!(import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());
drop(import);
tx.write(()).await.unwrap_err();
}

// Now cancel the import, despite it actually being done. This should
// realize that the cancellation is racing completion.
drop(import);
});

// Race an import's cancellation with a pending status code indicating that
// it's transitioning from started => returned.
println!("race cancellation with pending status code");
wit_bindgen::block_on(async {
// Start a subtask and get it into the "started" state
let (tx1, rx1) = wit_future::new(|| unreachable!());
let mut started_import = Box::pin(pending_import(rx1));
assert!(started_import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// force the next subtask to start out in the "starting" state, not the
// "started" state.
backpressure_set(true);
let (tx2, rx2) = wit_future::new(|| unreachable!());
let mut starting_import = Box::pin(pending_import(rx2));
assert!(starting_import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// Disable backpressure in the other component which will let the
// `starting_import`, previously in the "STARTING" state, get a queued up
// notification that it's entered the "STARTED" state.
backpressure_set(false);
for _ in 0..5 {
yield_async().await;
println!("test cancelling an import before it starts");
{
let (tx, rx) = wit_future::new(|| unreachable!());
let import = Box::pin(pending_import(rx));
drop(import);
tx.write(()).await.unwrap_err();
}

// Now cancel the `starting_import`. This should correctly pick up the
// STARTING => STARTED state transition and handle that correctly.
drop(starting_import);
println!("test cancelling an import in the started state");
{
let (tx1, rx1) = wit_future::new(|| unreachable!());
let (tx2, rx2) = wit_future::new(|| unreachable!());

// create a task in the "started" state, but don't complete it yet
let mut started_import = Box::pin(pending_import(rx1));
assert!(started_import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// request the other component sets its backpressure flag meaning we
// won't be able to create new tasks in the "started" state.
backpressure_set(true);
let mut starting_import = Box::pin(pending_import(rx2));
assert!(starting_import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// Now cancel the "starting" import. This should notably drop handles in
// arguments since they get re-acquired during cancellation
drop(starting_import);

// cancel our in-progress export
drop(started_import);

backpressure_set(false);

// both channels should be dropped
tx1.write(()).await.unwrap_err();
tx2.write(()).await.unwrap_err();
}

// Our future to the import we cancelled shouldn't be able to complete
// its write.
tx2.write(()).await.unwrap_err();
// Race an import's cancellation with a status code saying it's done.
println!("test cancellation with a status code saying it's done");
{
// Start a subtask and get it into the "started" state
let (tx, rx) = wit_future::new(|| unreachable!());
let mut import = Box::pin(pending_import(rx));
assert!(import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// Complete the subtask, but don't see the completion in Rust yet.
tx.write(()).await.unwrap();

// Let the subtask's completion notification make its way to our task
// here.
for _ in 0..5 {
yield_async().await;
}

// Now cancel the import, despite it actually being done. This should
// realize that the cancellation is racing completion.
drop(import);
}

// Complete the other import normally just to assert that it's not
// cancelled and able to proceed as usual.
tx1.write(()).await.unwrap();
started_import.await;
});
// Race an import's cancellation with a pending status code indicating that
// it's transitioning from started => returned.
println!("race cancellation with pending status code");
{
// Start a subtask and get it into the "started" state
let (tx1, rx1) = wit_future::new(|| unreachable!());
let mut started_import = Box::pin(pending_import(rx1));
assert!(started_import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// force the next subtask to start out in the "starting" state, not the
// "started" state.
backpressure_set(true);
let (tx2, rx2) = wit_future::new(|| unreachable!());
let mut starting_import = Box::pin(pending_import(rx2));
assert!(starting_import
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref()))
.is_pending());

// Disable backpressure in the other component which will let the
// `starting_import`, previously in the "STARTING" state, get a queued up
// notification that it's entered the "STARTED" state.
backpressure_set(false);
for _ in 0..5 {
yield_async().await;
}

// Now cancel the `starting_import`. This should correctly pick up the
// STARTING => STARTED state transition and handle that correctly.
drop(starting_import);

// Our future to the import we cancelled shouldn't be able to complete
// its write.
tx2.write(()).await.unwrap_err();

// Complete the other import normally just to assert that it's not
// cancelled and able to proceed as usual.
tx1.write(()).await.unwrap();
started_import.await;
}
}
}
2 changes: 2 additions & 0 deletions tests/runtime-async/async/cancel-import/test.wit
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ world test {

world runner {
import i;

export run: async func();
}
4 changes: 2 additions & 2 deletions tests/runtime-async/async/future-cancel-read/runner.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//@ args = '--rename my:test/i=test'
//@ args = '--rename my:test/i=test --async=-run'

#include <assert.h>
#include <runner.h>

int main() {
void exports_runner_run() {
{
test_future_u32_writer_t writer;
test_future_u32_t reader = test_future_u32_new(&writer);
Expand Down
Loading