Path: blob/main/crates/wasi/tests/all/p2/async_.rs
1692 views
use crate::store::{Ctx, MyWasiCtx};1use anyhow::Result;2use std::path::Path;3use test_programs_artifacts::*;4use wasmtime::component::{Component, Linker};5use wasmtime_wasi::p2::add_to_linker_async;6use wasmtime_wasi::p2::bindings::Command;78async fn run(path: &str, inherit_stdio: bool) -> Result<()> {9let path = Path::new(path);10let name = path.file_stem().unwrap().to_str().unwrap();11let engine = test_programs_artifacts::engine(|config| {12config.async_support(true);13});14let mut linker = Linker::new(&engine);15add_to_linker_async(&mut linker)?;1617let (mut store, _td) = Ctx::new(&engine, name, |builder| {18if inherit_stdio {19builder.inherit_stdio();20}21MyWasiCtx {22wasi: builder.build(),23table: Default::default(),24}25})?;26let component = Component::from_file(&engine, path)?;27let command = Command::instantiate_async(&mut store, &component, &linker).await?;28command29.wasi_cli_run()30.call_run(&mut store)31.await?32.map_err(|()| anyhow::anyhow!("run returned a failure"))33}3435foreach_preview1!(assert_test_exists);36foreach_preview2!(assert_test_exists);3738// Below here is mechanical: there should be one test for every binary in39// wasi-tests.40#[test_log::test(tokio::test(flavor = "multi_thread"))]41async fn preview1_big_random_buf() {42run(PREVIEW1_BIG_RANDOM_BUF_COMPONENT, false).await.unwrap()43}44#[test_log::test(tokio::test(flavor = "multi_thread"))]45async fn preview1_clock_time_get() {46run(PREVIEW1_CLOCK_TIME_GET_COMPONENT, false).await.unwrap()47}48#[test_log::test(tokio::test(flavor = "multi_thread"))]49async fn preview1_close_preopen() {50run(PREVIEW1_CLOSE_PREOPEN_COMPONENT, false).await.unwrap()51}52#[test_log::test(tokio::test(flavor = "multi_thread"))]53async fn preview1_dangling_fd() {54run(PREVIEW1_DANGLING_FD_COMPONENT, false).await.unwrap()55}56#[test_log::test(tokio::test(flavor = "multi_thread"))]57async fn preview1_dangling_symlink() {58run(PREVIEW1_DANGLING_SYMLINK_COMPONENT, false)59.await60.unwrap()61}62#[test_log::test(tokio::test(flavor = "multi_thread"))]63async fn preview1_directory_seek() {64run(PREVIEW1_DIRECTORY_SEEK_COMPONENT, false).await.unwrap()65}66#[test_log::test(tokio::test(flavor = "multi_thread"))]67async fn preview1_dir_fd_op_failures() {68run(PREVIEW1_DIR_FD_OP_FAILURES_COMPONENT, false)69.await70.unwrap()71}72#[test_log::test(tokio::test(flavor = "multi_thread"))]73async fn preview1_fd_advise() {74run(PREVIEW1_FD_ADVISE_COMPONENT, false).await.unwrap()75}76#[test_log::test(tokio::test(flavor = "multi_thread"))]77async fn preview1_fd_filestat_get() {78run(PREVIEW1_FD_FILESTAT_GET_COMPONENT, false)79.await80.unwrap()81}82#[test_log::test(tokio::test(flavor = "multi_thread"))]83async fn preview1_fd_filestat_set() {84run(PREVIEW1_FD_FILESTAT_SET_COMPONENT, false)85.await86.unwrap()87}88#[test_log::test(tokio::test(flavor = "multi_thread"))]89async fn preview1_fd_flags_set() {90run(PREVIEW1_FD_FLAGS_SET_COMPONENT, false).await.unwrap()91}92#[test_log::test(tokio::test(flavor = "multi_thread"))]93async fn preview1_fd_readdir() {94run(PREVIEW1_FD_READDIR_COMPONENT, false).await.unwrap()95}96#[test_log::test(tokio::test(flavor = "multi_thread"))]97async fn preview1_file_allocate() {98run(PREVIEW1_FILE_ALLOCATE_COMPONENT, false).await.unwrap()99}100#[test_log::test(tokio::test(flavor = "multi_thread"))]101async fn preview1_file_pread_pwrite() {102run(PREVIEW1_FILE_PREAD_PWRITE_COMPONENT, false)103.await104.unwrap()105}106#[test_log::test(tokio::test(flavor = "multi_thread"))]107async fn preview1_file_read_write() {108run(PREVIEW1_FILE_READ_WRITE_COMPONENT, false)109.await110.unwrap()111}112#[test_log::test(tokio::test(flavor = "multi_thread"))]113async fn preview1_file_seek_tell() {114run(PREVIEW1_FILE_SEEK_TELL_COMPONENT, false).await.unwrap()115}116#[test_log::test(tokio::test(flavor = "multi_thread"))]117async fn preview1_file_truncation() {118run(PREVIEW1_FILE_TRUNCATION_COMPONENT, false)119.await120.unwrap()121}122#[test_log::test(tokio::test(flavor = "multi_thread"))]123async fn preview1_file_unbuffered_write() {124run(PREVIEW1_FILE_UNBUFFERED_WRITE_COMPONENT, false)125.await126.unwrap()127}128#[test_log::test(tokio::test(flavor = "multi_thread"))]129async fn preview1_interesting_paths() {130run(PREVIEW1_INTERESTING_PATHS_COMPONENT, true)131.await132.unwrap()133}134#[test_log::test(tokio::test(flavor = "multi_thread"))]135async fn preview1_regular_file_isatty() {136run(PREVIEW1_REGULAR_FILE_ISATTY_COMPONENT, false)137.await138.unwrap()139}140#[test_log::test(tokio::test(flavor = "multi_thread"))]141async fn preview1_nofollow_errors() {142run(PREVIEW1_NOFOLLOW_ERRORS_COMPONENT, false)143.await144.unwrap()145}146#[test_log::test(tokio::test(flavor = "multi_thread"))]147async fn preview1_overwrite_preopen() {148run(PREVIEW1_OVERWRITE_PREOPEN_COMPONENT, false)149.await150.unwrap()151}152#[test_log::test(tokio::test(flavor = "multi_thread"))]153async fn preview1_path_exists() {154run(PREVIEW1_PATH_EXISTS_COMPONENT, false).await.unwrap()155}156#[test_log::test(tokio::test(flavor = "multi_thread"))]157async fn preview1_path_filestat() {158run(PREVIEW1_PATH_FILESTAT_COMPONENT, false).await.unwrap()159}160#[test_log::test(tokio::test(flavor = "multi_thread"))]161async fn preview1_path_link() {162run(PREVIEW1_PATH_LINK_COMPONENT, false).await.unwrap()163}164#[test_log::test(tokio::test(flavor = "multi_thread"))]165async fn preview1_path_open_create_existing() {166run(PREVIEW1_PATH_OPEN_CREATE_EXISTING_COMPONENT, false)167.await168.unwrap()169}170#[test_log::test(tokio::test(flavor = "multi_thread"))]171async fn preview1_path_open_read_write() {172run(PREVIEW1_PATH_OPEN_READ_WRITE_COMPONENT, false)173.await174.unwrap()175}176#[test_log::test(tokio::test(flavor = "multi_thread"))]177async fn preview1_path_open_dirfd_not_dir() {178run(PREVIEW1_PATH_OPEN_DIRFD_NOT_DIR_COMPONENT, false)179.await180.unwrap()181}182#[test_log::test(tokio::test(flavor = "multi_thread"))]183async fn preview1_path_open_missing() {184run(PREVIEW1_PATH_OPEN_MISSING_COMPONENT, false)185.await186.unwrap()187}188#[test_log::test(tokio::test(flavor = "multi_thread"))]189async fn preview1_path_open_nonblock() {190run(PREVIEW1_PATH_OPEN_NONBLOCK_COMPONENT, false)191.await192.unwrap()193}194#[test_log::test(tokio::test(flavor = "multi_thread"))]195async fn preview1_path_rename_dir_trailing_slashes() {196run(PREVIEW1_PATH_RENAME_DIR_TRAILING_SLASHES_COMPONENT, false)197.await198.unwrap()199}200#[test_log::test(tokio::test(flavor = "multi_thread"))]201async fn preview1_path_rename() {202run(PREVIEW1_PATH_RENAME_COMPONENT, false).await.unwrap()203}204#[test_log::test(tokio::test(flavor = "multi_thread"))]205async fn preview1_path_symlink_trailing_slashes() {206run(PREVIEW1_PATH_SYMLINK_TRAILING_SLASHES_COMPONENT, false)207.await208.unwrap()209}210#[test_log::test(tokio::test(flavor = "multi_thread"))]211async fn preview1_poll_oneoff_files() {212run(PREVIEW1_POLL_ONEOFF_FILES_COMPONENT, false)213.await214.unwrap()215}216217#[test_log::test(tokio::test(flavor = "multi_thread"))]218async fn preview1_poll_oneoff_stdio() {219run(PREVIEW1_POLL_ONEOFF_STDIO_COMPONENT, true)220.await221.unwrap()222}223#[test_log::test(tokio::test(flavor = "multi_thread"))]224async fn preview1_readlink() {225run(PREVIEW1_READLINK_COMPONENT, false).await.unwrap()226}227#[test_log::test(tokio::test(flavor = "multi_thread"))]228async fn preview1_remove_directory() {229run(PREVIEW1_REMOVE_DIRECTORY_COMPONENT, false)230.await231.unwrap()232}233#[test_log::test(tokio::test(flavor = "multi_thread"))]234async fn preview1_remove_nonempty_directory() {235run(PREVIEW1_REMOVE_NONEMPTY_DIRECTORY_COMPONENT, false)236.await237.unwrap()238}239#[test_log::test(tokio::test(flavor = "multi_thread"))]240async fn preview1_renumber() {241run(PREVIEW1_RENUMBER_COMPONENT, false).await.unwrap()242}243#[test_log::test(tokio::test(flavor = "multi_thread"))]244async fn preview1_sched_yield() {245run(PREVIEW1_SCHED_YIELD_COMPONENT, false).await.unwrap()246}247#[test_log::test(tokio::test(flavor = "multi_thread"))]248async fn preview1_stdio() {249run(PREVIEW1_STDIO_COMPONENT, false).await.unwrap()250}251#[test_log::test(tokio::test(flavor = "multi_thread"))]252async fn preview1_stdio_isatty() {253// If the test process is setup such that stdio is a terminal:254if test_programs_artifacts::stdio_is_terminal() {255// Inherit stdio, test asserts each is not tty:256run(PREVIEW1_STDIO_ISATTY_COMPONENT, true).await.unwrap()257}258}259#[test_log::test(tokio::test(flavor = "multi_thread"))]260async fn preview1_stdio_not_isatty() {261// Don't inherit stdio, test asserts each is not tty:262run(PREVIEW1_STDIO_NOT_ISATTY_COMPONENT, false)263.await264.unwrap()265}266#[test_log::test(tokio::test(flavor = "multi_thread"))]267async fn preview1_symlink_create() {268run(PREVIEW1_SYMLINK_CREATE_COMPONENT, false).await.unwrap()269}270#[test_log::test(tokio::test(flavor = "multi_thread"))]271async fn preview1_symlink_filestat() {272run(PREVIEW1_SYMLINK_FILESTAT_COMPONENT, false)273.await274.unwrap()275}276#[test_log::test(tokio::test(flavor = "multi_thread"))]277async fn preview1_symlink_loop() {278run(PREVIEW1_SYMLINK_LOOP_COMPONENT, false).await.unwrap()279}280#[test_log::test(tokio::test(flavor = "multi_thread"))]281async fn preview1_unlink_file_trailing_slashes() {282run(PREVIEW1_UNLINK_FILE_TRAILING_SLASHES_COMPONENT, false)283.await284.unwrap()285}286#[test_log::test(tokio::test(flavor = "multi_thread"))]287async fn preview1_path_open_preopen() {288run(PREVIEW1_PATH_OPEN_PREOPEN_COMPONENT, false)289.await290.unwrap()291}292#[test_log::test(tokio::test(flavor = "multi_thread"))]293async fn preview1_unicode_output() {294run(PREVIEW1_UNICODE_OUTPUT_COMPONENT, true).await.unwrap()295}296#[test_log::test(tokio::test(flavor = "multi_thread"))]297async fn preview1_file_write() {298run(PREVIEW1_FILE_WRITE_COMPONENT, false).await.unwrap()299}300#[test_log::test(tokio::test(flavor = "multi_thread"))]301async fn preview1_path_open_lots() {302run(PREVIEW1_PATH_OPEN_LOTS_COMPONENT, false).await.unwrap()303}304305#[test_log::test(tokio::test(flavor = "multi_thread"))]306async fn preview2_sleep() {307run(PREVIEW2_SLEEP_COMPONENT, false).await.unwrap()308}309#[test_log::test(tokio::test(flavor = "multi_thread"))]310async fn preview2_random() {311run(PREVIEW2_RANDOM_COMPONENT, false).await.unwrap()312}313#[test_log::test(tokio::test(flavor = "multi_thread"))]314async fn preview2_ip_name_lookup() {315run(PREVIEW2_IP_NAME_LOOKUP_COMPONENT, false).await.unwrap()316}317#[test_log::test(tokio::test(flavor = "multi_thread"))]318async fn preview2_tcp_sockopts() {319run(PREVIEW2_TCP_SOCKOPTS_COMPONENT, false).await.unwrap()320}321#[test_log::test(tokio::test(flavor = "multi_thread"))]322async fn preview2_tcp_sample_application() {323run(PREVIEW2_TCP_SAMPLE_APPLICATION_COMPONENT, false)324.await325.unwrap()326}327#[test_log::test(tokio::test(flavor = "multi_thread"))]328async fn preview2_tcp_states() {329run(PREVIEW2_TCP_STATES_COMPONENT, false).await.unwrap()330}331#[test_log::test(tokio::test(flavor = "multi_thread"))]332async fn preview2_tcp_streams() {333run(PREVIEW2_TCP_STREAMS_COMPONENT, false).await.unwrap()334}335#[test_log::test(tokio::test(flavor = "multi_thread"))]336async fn preview2_tcp_bind() {337run(PREVIEW2_TCP_BIND_COMPONENT, false).await.unwrap()338}339#[test_log::test(tokio::test(flavor = "multi_thread"))]340async fn preview2_tcp_connect() {341run(PREVIEW2_TCP_CONNECT_COMPONENT, false).await.unwrap()342}343#[test_log::test(tokio::test(flavor = "multi_thread"))]344async fn preview2_udp_sockopts() {345run(PREVIEW2_UDP_SOCKOPTS_COMPONENT, false).await.unwrap()346}347#[test_log::test(tokio::test(flavor = "multi_thread"))]348async fn preview2_udp_sample_application() {349run(PREVIEW2_UDP_SAMPLE_APPLICATION_COMPONENT, false)350.await351.unwrap()352}353#[test_log::test(tokio::test(flavor = "multi_thread"))]354async fn preview2_udp_states() {355run(PREVIEW2_UDP_STATES_COMPONENT, false).await.unwrap()356}357#[test_log::test(tokio::test(flavor = "multi_thread"))]358async fn preview2_udp_bind() {359run(PREVIEW2_UDP_BIND_COMPONENT, false).await.unwrap()360}361#[test_log::test(tokio::test(flavor = "multi_thread"))]362async fn preview2_udp_connect() {363run(PREVIEW2_UDP_CONNECT_COMPONENT, false).await.unwrap()364}365#[test_log::test(tokio::test(flavor = "multi_thread"))]366async fn preview2_stream_pollable_correct() {367run(PREVIEW2_STREAM_POLLABLE_CORRECT_COMPONENT, false)368.await369.unwrap()370}371#[test_log::test(tokio::test(flavor = "multi_thread"))]372async fn preview2_stream_pollable_traps() {373let e = run(PREVIEW2_STREAM_POLLABLE_TRAPS_COMPONENT, false)374.await375.unwrap_err();376assert_eq!(377format!("{}", e.source().expect("trap source")),378"resource has children"379)380}381#[test_log::test(tokio::test(flavor = "multi_thread"))]382async fn preview2_pollable_correct() {383run(PREVIEW2_POLLABLE_CORRECT_COMPONENT, false)384.await385.unwrap()386}387#[test_log::test(tokio::test(flavor = "multi_thread"))]388async fn preview2_pollable_traps() {389let e = run(PREVIEW2_POLLABLE_TRAPS_COMPONENT, false)390.await391.unwrap_err();392assert_eq!(393format!("{}", e.source().expect("trap source")),394"empty poll list"395)396}397#[test_log::test(tokio::test(flavor = "multi_thread"))]398async fn preview2_adapter_badfd() {399run(PREVIEW2_ADAPTER_BADFD_COMPONENT, false).await.unwrap()400}401#[test_log::test(tokio::test(flavor = "multi_thread"))]402async fn preview2_file_read_write() {403run(PREVIEW2_FILE_READ_WRITE_COMPONENT, false)404.await405.unwrap()406}407408409