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