Path: blob/main/crates/wasi/tests/all/p2/async_.rs
3129 views
use crate::store::{Ctx, MyWasiCtx};1use std::path::Path;2use test_programs_artifacts::*;3use wasmtime::Result;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| {});12let mut linker = Linker::new(&engine);13add_to_linker_async(&mut linker)?;1415let (mut store, _td) = Ctx::new(&engine, name, |builder| {16if inherit_stdio {17builder.inherit_stdio();18}19MyWasiCtx {20wasi: builder.build(),21table: Default::default(),22}23})?;24let component = Component::from_file(&engine, path)?;25let command = Command::instantiate_async(&mut store, &component, &linker).await?;26command27.wasi_cli_run()28.call_run(&mut store)29.await?30.map_err(|()| wasmtime::format_err!("run returned a failure"))31}3233foreach_p1!(assert_test_exists);34foreach_p2!(assert_test_exists);3536// Below here is mechanical: there should be one test for every binary in37// wasi-tests.38#[test_log::test(tokio::test(flavor = "multi_thread"))]39async fn p1_big_random_buf() {40run(P1_BIG_RANDOM_BUF_COMPONENT, false).await.unwrap()41}42#[test_log::test(tokio::test(flavor = "multi_thread"))]43async fn p1_clock_time_get() {44run(P1_CLOCK_TIME_GET_COMPONENT, false).await.unwrap()45}46#[test_log::test(tokio::test(flavor = "multi_thread"))]47async fn p1_close_preopen() {48run(P1_CLOSE_PREOPEN_COMPONENT, false).await.unwrap()49}50#[test_log::test(tokio::test(flavor = "multi_thread"))]51async fn p1_dangling_fd() {52run(P1_DANGLING_FD_COMPONENT, false).await.unwrap()53}54#[test_log::test(tokio::test(flavor = "multi_thread"))]55async fn p1_dangling_symlink() {56run(P1_DANGLING_SYMLINK_COMPONENT, false).await.unwrap()57}58#[test_log::test(tokio::test(flavor = "multi_thread"))]59async fn p1_directory_seek() {60run(P1_DIRECTORY_SEEK_COMPONENT, false).await.unwrap()61}62#[test_log::test(tokio::test(flavor = "multi_thread"))]63async fn p1_dir_fd_op_failures() {64run(P1_DIR_FD_OP_FAILURES_COMPONENT, false).await.unwrap()65}66#[test_log::test(tokio::test(flavor = "multi_thread"))]67async fn p1_fd_advise() {68run(P1_FD_ADVISE_COMPONENT, false).await.unwrap()69}70#[test_log::test(tokio::test(flavor = "multi_thread"))]71async fn p1_fd_filestat_get() {72run(P1_FD_FILESTAT_GET_COMPONENT, false).await.unwrap()73}74#[test_log::test(tokio::test(flavor = "multi_thread"))]75async fn p1_fd_filestat_set() {76run(P1_FD_FILESTAT_SET_COMPONENT, false).await.unwrap()77}78#[test_log::test(tokio::test(flavor = "multi_thread"))]79async fn p1_fd_flags_set() {80run(P1_FD_FLAGS_SET_COMPONENT, false).await.unwrap()81}82#[test_log::test(tokio::test(flavor = "multi_thread"))]83async fn p1_fd_readdir() {84run(P1_FD_READDIR_COMPONENT, false).await.unwrap()85}86#[test_log::test(tokio::test(flavor = "multi_thread"))]87async fn p1_file_allocate() {88run(P1_FILE_ALLOCATE_COMPONENT, false).await.unwrap()89}90#[test_log::test(tokio::test(flavor = "multi_thread"))]91async fn p1_file_pread_pwrite() {92run(P1_FILE_PREAD_PWRITE_COMPONENT, false).await.unwrap()93}94#[test_log::test(tokio::test(flavor = "multi_thread"))]95async fn p1_file_read_write() {96run(P1_FILE_READ_WRITE_COMPONENT, false).await.unwrap()97}98#[test_log::test(tokio::test(flavor = "multi_thread"))]99async fn p1_file_seek_tell() {100run(P1_FILE_SEEK_TELL_COMPONENT, false).await.unwrap()101}102#[test_log::test(tokio::test(flavor = "multi_thread"))]103async fn p1_file_truncation() {104run(P1_FILE_TRUNCATION_COMPONENT, false).await.unwrap()105}106#[test_log::test(tokio::test(flavor = "multi_thread"))]107async fn p1_file_unbuffered_write() {108run(P1_FILE_UNBUFFERED_WRITE_COMPONENT, false)109.await110.unwrap()111}112#[test_log::test(tokio::test(flavor = "multi_thread"))]113async fn p1_interesting_paths() {114run(P1_INTERESTING_PATHS_COMPONENT, true).await.unwrap()115}116#[test_log::test(tokio::test(flavor = "multi_thread"))]117async fn p1_regular_file_isatty() {118run(P1_REGULAR_FILE_ISATTY_COMPONENT, false).await.unwrap()119}120#[test_log::test(tokio::test(flavor = "multi_thread"))]121async fn p1_nofollow_errors() {122run(P1_NOFOLLOW_ERRORS_COMPONENT, false).await.unwrap()123}124#[test_log::test(tokio::test(flavor = "multi_thread"))]125async fn p1_overwrite_preopen() {126run(P1_OVERWRITE_PREOPEN_COMPONENT, false).await.unwrap()127}128#[test_log::test(tokio::test(flavor = "multi_thread"))]129async fn p1_path_exists() {130run(P1_PATH_EXISTS_COMPONENT, false).await.unwrap()131}132#[test_log::test(tokio::test(flavor = "multi_thread"))]133async fn p1_path_filestat() {134run(P1_PATH_FILESTAT_COMPONENT, false).await.unwrap()135}136#[test_log::test(tokio::test(flavor = "multi_thread"))]137async fn p1_path_link() {138run(P1_PATH_LINK_COMPONENT, false).await.unwrap()139}140#[test_log::test(tokio::test(flavor = "multi_thread"))]141async fn p1_path_open_create_existing() {142run(P1_PATH_OPEN_CREATE_EXISTING_COMPONENT, false)143.await144.unwrap()145}146#[test_log::test(tokio::test(flavor = "multi_thread"))]147async fn p1_path_open_read_write() {148run(P1_PATH_OPEN_READ_WRITE_COMPONENT, false).await.unwrap()149}150#[test_log::test(tokio::test(flavor = "multi_thread"))]151async fn p1_path_open_dirfd_not_dir() {152run(P1_PATH_OPEN_DIRFD_NOT_DIR_COMPONENT, false)153.await154.unwrap()155}156#[test_log::test(tokio::test(flavor = "multi_thread"))]157async fn p1_path_open_missing() {158run(P1_PATH_OPEN_MISSING_COMPONENT, false).await.unwrap()159}160#[test_log::test(tokio::test(flavor = "multi_thread"))]161async fn p1_path_open_nonblock() {162run(P1_PATH_OPEN_NONBLOCK_COMPONENT, false).await.unwrap()163}164#[test_log::test(tokio::test(flavor = "multi_thread"))]165async fn p1_path_rename_dir_trailing_slashes() {166run(P1_PATH_RENAME_DIR_TRAILING_SLASHES_COMPONENT, false)167.await168.unwrap()169}170#[test_log::test(tokio::test(flavor = "multi_thread"))]171async fn p1_path_rename() {172run(P1_PATH_RENAME_COMPONENT, false).await.unwrap()173}174#[test_log::test(tokio::test(flavor = "multi_thread"))]175async fn p1_path_symlink_trailing_slashes() {176run(P1_PATH_SYMLINK_TRAILING_SLASHES_COMPONENT, false)177.await178.unwrap()179}180#[test_log::test(tokio::test(flavor = "multi_thread"))]181async fn p1_poll_oneoff_files() {182run(P1_POLL_ONEOFF_FILES_COMPONENT, false).await.unwrap()183}184185#[test_log::test(tokio::test(flavor = "multi_thread"))]186async fn p1_poll_oneoff_stdio() {187run(P1_POLL_ONEOFF_STDIO_COMPONENT, true).await.unwrap()188}189#[test_log::test(tokio::test(flavor = "multi_thread"))]190async fn p1_readlink() {191run(P1_READLINK_COMPONENT, false).await.unwrap()192}193#[test_log::test(tokio::test(flavor = "multi_thread"))]194async fn p1_remove_directory() {195run(P1_REMOVE_DIRECTORY_COMPONENT, false).await.unwrap()196}197#[test_log::test(tokio::test(flavor = "multi_thread"))]198async fn p1_remove_nonempty_directory() {199run(P1_REMOVE_NONEMPTY_DIRECTORY_COMPONENT, false)200.await201.unwrap()202}203#[test_log::test(tokio::test(flavor = "multi_thread"))]204async fn p1_renumber() {205run(P1_RENUMBER_COMPONENT, false).await.unwrap()206}207#[test_log::test(tokio::test(flavor = "multi_thread"))]208async fn p1_sched_yield() {209run(P1_SCHED_YIELD_COMPONENT, false).await.unwrap()210}211#[test_log::test(tokio::test(flavor = "multi_thread"))]212async fn p1_stdio() {213run(P1_STDIO_COMPONENT, false).await.unwrap()214}215#[test_log::test(tokio::test(flavor = "multi_thread"))]216async fn p1_stdio_isatty() {217// If the test process is setup such that stdio is a terminal:218if test_programs_artifacts::stdio_is_terminal() {219// Inherit stdio, test asserts each is not tty:220run(P1_STDIO_ISATTY_COMPONENT, true).await.unwrap()221}222}223#[test_log::test(tokio::test(flavor = "multi_thread"))]224async fn p1_stdio_not_isatty() {225// Don't inherit stdio, test asserts each is not tty:226run(P1_STDIO_NOT_ISATTY_COMPONENT, false).await.unwrap()227}228#[test_log::test(tokio::test(flavor = "multi_thread"))]229async fn p1_symlink_create() {230run(P1_SYMLINK_CREATE_COMPONENT, false).await.unwrap()231}232#[test_log::test(tokio::test(flavor = "multi_thread"))]233async fn p1_symlink_filestat() {234run(P1_SYMLINK_FILESTAT_COMPONENT, false).await.unwrap()235}236#[test_log::test(tokio::test(flavor = "multi_thread"))]237async fn p1_symlink_loop() {238run(P1_SYMLINK_LOOP_COMPONENT, false).await.unwrap()239}240#[test_log::test(tokio::test(flavor = "multi_thread"))]241async fn p1_unlink_file_trailing_slashes() {242run(P1_UNLINK_FILE_TRAILING_SLASHES_COMPONENT, false)243.await244.unwrap()245}246#[test_log::test(tokio::test(flavor = "multi_thread"))]247async fn p1_path_open_preopen() {248run(P1_PATH_OPEN_PREOPEN_COMPONENT, false).await.unwrap()249}250#[test_log::test(tokio::test(flavor = "multi_thread"))]251async fn p1_unicode_output() {252run(P1_UNICODE_OUTPUT_COMPONENT, true).await.unwrap()253}254#[test_log::test(tokio::test(flavor = "multi_thread"))]255async fn p1_file_write() {256run(P1_FILE_WRITE_COMPONENT, false).await.unwrap()257}258#[test_log::test(tokio::test(flavor = "multi_thread"))]259async fn p1_path_open_lots() {260run(P1_PATH_OPEN_LOTS_COMPONENT, false).await.unwrap()261}262263#[test_log::test(tokio::test(flavor = "multi_thread"))]264async fn p2_sleep() {265run(P2_SLEEP_COMPONENT, false).await.unwrap()266}267#[test_log::test(tokio::test(flavor = "multi_thread"))]268async fn p2_random() {269run(P2_RANDOM_COMPONENT, false).await.unwrap()270}271#[test_log::test(tokio::test(flavor = "multi_thread"))]272async fn p2_ip_name_lookup() {273run(P2_IP_NAME_LOOKUP_COMPONENT, false).await.unwrap()274}275#[test_log::test(tokio::test(flavor = "multi_thread"))]276async fn p2_tcp_sockopts() {277run(P2_TCP_SOCKOPTS_COMPONENT, false).await.unwrap()278}279#[test_log::test(tokio::test(flavor = "multi_thread"))]280async fn p2_tcp_sample_application() {281run(P2_TCP_SAMPLE_APPLICATION_COMPONENT, false)282.await283.unwrap()284}285#[test_log::test(tokio::test(flavor = "multi_thread"))]286async fn p2_tcp_states() {287run(P2_TCP_STATES_COMPONENT, false).await.unwrap()288}289#[test_log::test(tokio::test(flavor = "multi_thread"))]290async fn p2_tcp_streams() {291run(P2_TCP_STREAMS_COMPONENT, false).await.unwrap()292}293#[test_log::test(tokio::test(flavor = "multi_thread"))]294async fn p2_tcp_bind() {295run(P2_TCP_BIND_COMPONENT, false).await.unwrap()296}297#[test_log::test(tokio::test(flavor = "multi_thread"))]298async fn p2_tcp_connect() {299run(P2_TCP_CONNECT_COMPONENT, false).await.unwrap()300}301#[test_log::test(tokio::test(flavor = "multi_thread"))]302async fn p2_tcp_listen() {303run(P2_TCP_LISTEN_COMPONENT, false).await.unwrap()304}305#[test_log::test(tokio::test(flavor = "multi_thread"))]306async fn p2_udp_sockopts() {307run(P2_UDP_SOCKOPTS_COMPONENT, false).await.unwrap()308}309#[test_log::test(tokio::test(flavor = "multi_thread"))]310async fn p2_udp_sample_application() {311run(P2_UDP_SAMPLE_APPLICATION_COMPONENT, false)312.await313.unwrap()314}315#[test_log::test(tokio::test(flavor = "multi_thread"))]316async fn p2_udp_states() {317run(P2_UDP_STATES_COMPONENT, false).await.unwrap()318}319#[test_log::test(tokio::test(flavor = "multi_thread"))]320async fn p2_udp_bind() {321run(P2_UDP_BIND_COMPONENT, false).await.unwrap()322}323#[test_log::test(tokio::test(flavor = "multi_thread"))]324async fn p2_udp_connect() {325run(P2_UDP_CONNECT_COMPONENT, false).await.unwrap()326}327#[test_log::test(tokio::test(flavor = "multi_thread"))]328async fn p2_stream_pollable_correct() {329run(P2_STREAM_POLLABLE_CORRECT_COMPONENT, false)330.await331.unwrap()332}333#[test_log::test(tokio::test(flavor = "multi_thread"))]334async fn p2_stream_pollable_traps() {335let e = run(P2_STREAM_POLLABLE_TRAPS_COMPONENT, false)336.await337.unwrap_err();338assert_eq!(339format!("{}", e.source().expect("trap source")),340"resource has children"341)342}343#[test_log::test(tokio::test(flavor = "multi_thread"))]344async fn p2_pollable_correct() {345run(P2_POLLABLE_CORRECT_COMPONENT, false).await.unwrap()346}347#[test_log::test(tokio::test(flavor = "multi_thread"))]348async fn p2_pollable_traps() {349let e = run(P2_POLLABLE_TRAPS_COMPONENT, false).await.unwrap_err();350assert_eq!(351format!("{}", e.source().expect("trap source")),352"empty poll list"353)354}355#[test_log::test(tokio::test(flavor = "multi_thread"))]356async fn p2_adapter_badfd() {357run(P2_ADAPTER_BADFD_COMPONENT, false).await.unwrap()358}359#[test_log::test(tokio::test(flavor = "multi_thread"))]360async fn p2_file_read_write() {361run(P2_FILE_READ_WRITE_COMPONENT, false).await.unwrap()362}363#[expect(364dead_code,365reason = "tested in the wasi-cli crate, satisfying foreach_api! macro"366)]367fn p1_cli_much_stdout() {}368369370