Path: blob/main/crates/wasi/tests/all/p2/sync.rs
1692 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(|()| anyhow::anyhow!("run returned a failure"))?;33}34Ok(())35}3637foreach_preview1!(assert_test_exists);38foreach_preview2!(assert_test_exists);3940// Below here is mechanical: there should be one test for every binary in41// wasi-tests.42#[test_log::test]43fn preview1_big_random_buf() {44run(PREVIEW1_BIG_RANDOM_BUF_COMPONENT, false).unwrap()45}46#[test_log::test]47fn preview1_clock_time_get() {48run(PREVIEW1_CLOCK_TIME_GET_COMPONENT, false).unwrap()49}50#[test_log::test]51fn preview1_close_preopen() {52run(PREVIEW1_CLOSE_PREOPEN_COMPONENT, false).unwrap()53}54#[test_log::test]55fn preview1_dangling_fd() {56run(PREVIEW1_DANGLING_FD_COMPONENT, false).unwrap()57}58#[test_log::test]59fn preview1_dangling_symlink() {60run(PREVIEW1_DANGLING_SYMLINK_COMPONENT, false).unwrap()61}62#[test_log::test]63fn preview1_directory_seek() {64run(PREVIEW1_DIRECTORY_SEEK_COMPONENT, false).unwrap()65}66#[test_log::test]67fn preview1_dir_fd_op_failures() {68run(PREVIEW1_DIR_FD_OP_FAILURES_COMPONENT, false).unwrap()69}70#[test_log::test]71fn preview1_fd_advise() {72run(PREVIEW1_FD_ADVISE_COMPONENT, false).unwrap()73}74#[test_log::test]75fn preview1_fd_filestat_get() {76run(PREVIEW1_FD_FILESTAT_GET_COMPONENT, false).unwrap()77}78#[test_log::test]79fn preview1_fd_filestat_set() {80run(PREVIEW1_FD_FILESTAT_SET_COMPONENT, false).unwrap()81}82#[test_log::test]83fn preview1_fd_flags_set() {84run(PREVIEW1_FD_FLAGS_SET_COMPONENT, false).unwrap()85}86#[test_log::test]87fn preview1_fd_readdir() {88run(PREVIEW1_FD_READDIR_COMPONENT, false).unwrap()89}90#[test_log::test]91fn preview1_file_allocate() {92run(PREVIEW1_FILE_ALLOCATE_COMPONENT, false).unwrap()93}94#[test_log::test]95fn preview1_file_pread_pwrite() {96run(PREVIEW1_FILE_PREAD_PWRITE_COMPONENT, false).unwrap()97}98#[test_log::test]99fn preview1_file_read_write() {100run(PREVIEW1_FILE_READ_WRITE_COMPONENT, false).unwrap()101}102#[test_log::test]103fn preview1_file_seek_tell() {104run(PREVIEW1_FILE_SEEK_TELL_COMPONENT, false).unwrap()105}106#[test_log::test]107fn preview1_file_truncation() {108run(PREVIEW1_FILE_TRUNCATION_COMPONENT, false).unwrap()109}110#[test_log::test]111fn preview1_file_unbuffered_write() {112run(PREVIEW1_FILE_UNBUFFERED_WRITE_COMPONENT, false).unwrap()113}114#[test_log::test]115fn preview1_interesting_paths() {116run(PREVIEW1_INTERESTING_PATHS_COMPONENT, false).unwrap()117}118#[test_log::test]119fn preview1_regular_file_isatty() {120run(PREVIEW1_REGULAR_FILE_ISATTY_COMPONENT, false).unwrap()121}122#[test_log::test]123fn preview1_nofollow_errors() {124run(PREVIEW1_NOFOLLOW_ERRORS_COMPONENT, false).unwrap()125}126#[test_log::test]127fn preview1_overwrite_preopen() {128run(PREVIEW1_OVERWRITE_PREOPEN_COMPONENT, false).unwrap()129}130#[test_log::test]131fn preview1_path_exists() {132run(PREVIEW1_PATH_EXISTS_COMPONENT, false).unwrap()133}134#[test_log::test]135fn preview1_path_filestat() {136run(PREVIEW1_PATH_FILESTAT_COMPONENT, false).unwrap()137}138#[test_log::test]139fn preview1_path_link() {140run(PREVIEW1_PATH_LINK_COMPONENT, false).unwrap()141}142#[test_log::test]143fn preview1_path_open_create_existing() {144run(PREVIEW1_PATH_OPEN_CREATE_EXISTING_COMPONENT, false).unwrap()145}146#[test_log::test]147fn preview1_path_open_read_write() {148run(PREVIEW1_PATH_OPEN_READ_WRITE_COMPONENT, false).unwrap()149}150#[test_log::test]151fn preview1_path_open_dirfd_not_dir() {152run(PREVIEW1_PATH_OPEN_DIRFD_NOT_DIR_COMPONENT, false).unwrap()153}154#[test_log::test]155fn preview1_path_open_missing() {156run(PREVIEW1_PATH_OPEN_MISSING_COMPONENT, false).unwrap()157}158#[test_log::test]159fn preview1_path_open_nonblock() {160run(PREVIEW1_PATH_OPEN_NONBLOCK_COMPONENT, false).unwrap()161}162#[test_log::test]163fn preview1_path_rename_dir_trailing_slashes() {164run(PREVIEW1_PATH_RENAME_DIR_TRAILING_SLASHES_COMPONENT, false).unwrap()165}166#[test_log::test]167fn preview1_path_rename() {168run(PREVIEW1_PATH_RENAME_COMPONENT, false).unwrap()169}170#[test_log::test]171fn preview1_path_symlink_trailing_slashes() {172run(PREVIEW1_PATH_SYMLINK_TRAILING_SLASHES_COMPONENT, false).unwrap()173}174#[test_log::test]175fn preview1_poll_oneoff_files() {176run(PREVIEW1_POLL_ONEOFF_FILES_COMPONENT, false).unwrap()177}178179#[test_log::test]180fn preview1_poll_oneoff_stdio() {181run(PREVIEW1_POLL_ONEOFF_STDIO_COMPONENT, true).unwrap()182}183#[test_log::test]184fn preview1_readlink() {185run(PREVIEW1_READLINK_COMPONENT, false).unwrap()186}187#[test_log::test]188fn preview1_remove_directory() {189run(PREVIEW1_REMOVE_DIRECTORY_COMPONENT, false).unwrap()190}191#[test_log::test]192fn preview1_remove_nonempty_directory() {193run(PREVIEW1_REMOVE_NONEMPTY_DIRECTORY_COMPONENT, false).unwrap()194}195#[test_log::test]196fn preview1_renumber() {197run(PREVIEW1_RENUMBER_COMPONENT, false).unwrap()198}199#[test_log::test]200fn preview1_sched_yield() {201run(PREVIEW1_SCHED_YIELD_COMPONENT, false).unwrap()202}203#[test_log::test]204fn preview1_stdio() {205run(PREVIEW1_STDIO_COMPONENT, false).unwrap()206}207#[test_log::test]208fn preview1_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(PREVIEW1_STDIO_ISATTY_COMPONENT, true).unwrap()213}214}215#[test_log::test]216fn preview1_stdio_not_isatty() {217// Don't inherit stdio, test asserts each is not tty:218run(PREVIEW1_STDIO_NOT_ISATTY_COMPONENT, false).unwrap()219}220#[test_log::test]221fn preview1_symlink_create() {222run(PREVIEW1_SYMLINK_CREATE_COMPONENT, false).unwrap()223}224#[test_log::test]225fn preview1_symlink_filestat() {226run(PREVIEW1_SYMLINK_FILESTAT_COMPONENT, false).unwrap()227}228#[test_log::test]229fn preview1_symlink_loop() {230run(PREVIEW1_SYMLINK_LOOP_COMPONENT, false).unwrap()231}232#[test_log::test]233fn preview1_unlink_file_trailing_slashes() {234run(PREVIEW1_UNLINK_FILE_TRAILING_SLASHES_COMPONENT, false).unwrap()235}236#[test_log::test]237fn preview1_path_open_preopen() {238run(PREVIEW1_PATH_OPEN_PREOPEN_COMPONENT, false).unwrap()239}240#[test_log::test]241fn preview1_unicode_output() {242run(PREVIEW1_UNICODE_OUTPUT_COMPONENT, true).unwrap()243}244#[test_log::test]245fn preview1_file_write() {246run(PREVIEW1_FILE_WRITE_COMPONENT, false).unwrap()247}248#[test_log::test]249fn preview1_path_open_lots() {250run(PREVIEW1_PATH_OPEN_LOTS_COMPONENT, false).unwrap()251}252253#[test_log::test]254fn preview2_sleep() {255run(PREVIEW2_SLEEP_COMPONENT, false).unwrap()256}257#[test_log::test]258fn preview2_random() {259run(PREVIEW2_RANDOM_COMPONENT, false).unwrap()260}261#[test_log::test]262fn preview2_ip_name_lookup() {263run(PREVIEW2_IP_NAME_LOOKUP_COMPONENT, false).unwrap()264}265#[test_log::test]266fn preview2_tcp_sockopts() {267run(PREVIEW2_TCP_SOCKOPTS_COMPONENT, false).unwrap()268}269#[test_log::test]270fn preview2_tcp_sample_application() {271run(PREVIEW2_TCP_SAMPLE_APPLICATION_COMPONENT, false).unwrap()272}273#[test_log::test]274fn preview2_tcp_states() {275run(PREVIEW2_TCP_STATES_COMPONENT, false).unwrap()276}277#[test_log::test]278fn preview2_tcp_streams() {279run(PREVIEW2_TCP_STREAMS_COMPONENT, false).unwrap()280}281#[test_log::test]282fn preview2_tcp_bind() {283run(PREVIEW2_TCP_BIND_COMPONENT, false).unwrap()284}285#[test_log::test]286fn preview2_tcp_connect() {287run(PREVIEW2_TCP_CONNECT_COMPONENT, false).unwrap()288}289#[test_log::test]290fn preview2_udp_sockopts() {291run(PREVIEW2_UDP_SOCKOPTS_COMPONENT, false).unwrap()292}293#[test_log::test]294fn preview2_udp_sample_application() {295run(PREVIEW2_UDP_SAMPLE_APPLICATION_COMPONENT, false).unwrap()296}297#[test_log::test]298fn preview2_udp_states() {299run(PREVIEW2_UDP_STATES_COMPONENT, false).unwrap()300}301#[test_log::test]302fn preview2_udp_bind() {303run(PREVIEW2_UDP_BIND_COMPONENT, false).unwrap()304}305#[test_log::test]306fn preview2_udp_connect() {307run(PREVIEW2_UDP_CONNECT_COMPONENT, false).unwrap()308}309#[test_log::test]310fn preview2_stream_pollable_correct() {311run(PREVIEW2_STREAM_POLLABLE_CORRECT_COMPONENT, false).unwrap()312}313#[test_log::test]314fn preview2_stream_pollable_traps() {315let e = run(PREVIEW2_STREAM_POLLABLE_TRAPS_COMPONENT, false).unwrap_err();316assert_eq!(317format!("{}", e.source().expect("trap source")),318"resource has children"319)320}321#[test_log::test]322fn preview2_pollable_correct() {323run(PREVIEW2_POLLABLE_CORRECT_COMPONENT, false).unwrap()324}325#[test_log::test]326fn preview2_pollable_traps() {327let e = run(PREVIEW2_POLLABLE_TRAPS_COMPONENT, false).unwrap_err();328assert_eq!(329format!("{}", e.source().expect("trap source")),330"empty poll list"331)332}333#[test_log::test]334fn preview2_adapter_badfd() {335run(PREVIEW2_ADAPTER_BADFD_COMPONENT, false).unwrap()336}337#[test_log::test]338fn preview2_file_read_write() {339run(PREVIEW2_FILE_READ_WRITE_COMPONENT, false).unwrap()340}341342343